{
  "id": "python/matplotlib-unicode-title-error",
  "signature": "UnicodeEncodeError: 'locale' codec can't encode character '\\u2014' in position 0: encoding error",
  "signature_zh": "UnicodeEncodeError: 'locale'编解码器无法在位置0编码字符'\\u2014'：编码错误",
  "regex": "UnicodeEncodeError:\\ 'locale'\\ codec\\ can't\\ encode\\ character\\ '\\\\u2014'\\ in\\ position\\ 0:\\ encoding\\ error",
  "domain": "python",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "Matplotlib's default backend tries to encode Unicode characters (e.g., em dash) using the system's locale encoding, which may not support them, especially on non-UTF-8 locales.",
  "root_cause_type": "generic",
  "root_cause_zh": "Matplotlib的默认后端尝试使用系统区域设置编码对Unicode字符（例如长破折号）进行编码，但该编码可能不支持这些字符，尤其是在非UTF-8区域设置下。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Setting plt.rcParams['font.sans-serif'] to a different font without addressing locale encoding",
      "why_fails": "Font change does not affect the encoding step; the error persists because the backend still uses locale for output.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding # -*- coding: utf-8 -*- to the script",
      "why_fails": "This only affects source file encoding, not runtime output encoding; the locale issue remains.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set the environment variable PYTHONIOENCODING to utf-8 before importing matplotlib",
      "success_rate": 0.85,
      "how": "import os; os.environ['PYTHONIOENCODING'] = 'utf-8'; import matplotlib.pyplot as plt",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a non-interactive backend like 'Agg'",
      "success_rate": 0.9,
      "how": "import matplotlib; matplotlib.use('Agg'); import matplotlib.pyplot as plt",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}