# TypeError: float() 参数必须是字符串或实数，而不是 'datetime.datetime'

- **ID:** `python/matplotlib-date-converter-error`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在未注册日期转换器的情况下将 naive datetime 对象直接传给 plot()，或在同一轴上混用 datetime 与数值。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (94% 成功率)
   ```
   import matplotlib.dates as mdates
dates = mdates.date2num(dt_list)
ax.plot(dates, values)
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
   ```
2. **** (90% 成功率)
   ```
   import pandas as pd
pd.plotting.register_matplotlib_converters()
ax.plot(df['date'], df['value'])
   ```

## 无效尝试

- **** — Strings become categorical labels, destroying the time axis ordering and tick formatting. (75% 失败率)
- **** — Mixing converted and unconverted series still triggers the float() error on the unconverted one. (60% 失败率)
