python
data_error
ai_generated
true
ValueError: Date ordinal 737791 is not a valid date for the Gregorian calendar.
ID: python/matplotlib-date-parser-error
80%Fix Rate
83%Confidence
0Evidence
2024-05-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
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.
generic中文
使用matplotlib的date2num或num2date时,传入的序数超出范围,通常是由于转换了公元1年之前或9999年之后的日期。
Workarounds
-
90% success Ensure dates are within the Gregorian calendar range (year 1 to 9999)
from datetime import datetime; date = datetime(2024, 1, 1); ordinal = matplotlib.dates.date2num(date)
-
85% success Use pandas date handling before plotting
import pandas as pd; dates = pd.date_range('2024-01-01', periods=10); plt.plot_date(dates, values)
Dead Ends
Common approaches that don't work:
-
Ignoring the error and continuing
80% fail
The plot may be incorrect or missing data points.
-
Using a different date library like datetime
50% fail
The error is in matplotlib's conversion; datetime may still produce valid ordinals but the issue is with the range.