# ValueError: 日期序数737791不是公历中的有效日期。

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

## 根因

使用matplotlib的date2num或num2date时，传入的序数超出范围，通常是由于转换了公元1年之前或9999年之后的日期。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |

## 解决方案

1. **Ensure dates are within the Gregorian calendar range (year 1 to 9999)** (90% 成功率)
   ```
   from datetime import datetime; date = datetime(2024, 1, 1); ordinal = matplotlib.dates.date2num(date)
   ```
2. **Use pandas date handling before plotting** (85% 成功率)
   ```
   import pandas as pd; dates = pd.date_range('2024-01-01', periods=10); plt.plot_date(dates, values)
   ```

## 无效尝试

- **Ignoring the error and continuing** — The plot may be incorrect or missing data points. (80% 失败率)
- **Using a different date library like datetime** — The error is in matplotlib's conversion; datetime may still produce valid ordinals but the issue is with the range. (50% 失败率)
