{
  "id": "python/matplotlib-date-converter-error",
  "signature": "TypeError: float() argument must be a string or a real number, not 'datetime.datetime'",
  "signature_zh": "TypeError: float() 参数必须是字符串或实数，而不是 'datetime.datetime'",
  "regex": "TypeError:\\ float\\(\\)\\ argument\\ must\\ be\\ a\\ string\\ or\\ a\\ real\\ number,\\ not\\ 'datetime\\.datetime'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Passing naive datetime objects directly to plot() without registering a date converter, or mixing datetime with numeric on the same axis.",
  "root_cause_type": "generic",
  "root_cause_zh": "在未注册日期转换器的情况下将 naive datetime 对象直接传给 plot()，或在同一轴上混用 datetime 与数值。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Strings become categorical labels, destroying the time axis ordering and tick formatting.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Mixing converted and unconverted series still triggers the float() error on the unconverted one.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.94,
      "how": "import matplotlib.dates as mdates\ndates = mdates.date2num(dt_list)\nax.plot(dates, values)\nax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "import pandas as pd\npd.plotting.register_matplotlib_converters()\nax.plot(df['date'], df['value'])",
      "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-04-09",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}