# ValueError: Date ordinal 737791 is not a valid date for the Gregorian calendar.

- **ID:** `python/matplotlib-date-parser-error`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Using matplotlib's date2num or num2date with an out-of-range ordinal, often due to incorrect conversion of dates before year 1 or after year 9999.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |

## Workarounds

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

## Dead Ends

- **Ignoring the error and continuing** — The plot may be incorrect or missing data points. (80% fail)
- **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% fail)
