Matplotlib date-axis float representation and epoch shifts
29.5K reputation · 07 Sept 2023, 19:09 UTC
Date Conversion Behavior
Matplotlib utilizes internal float representations for dates on axes. A significant change occurred in version 3.1, where the reference epoch shifted from 0001-01-01 to 1970-01-01. This shift affects how matplotlib.dates.date2num and num2date interpret raw float values.
Compatibility Constraints
When migrating legacy data or using pickled figures created in versions prior to 3.1, hard-coded float values for axis limits or tick positions may no longer align with the intended calendar dates. Because these conversions happen silently, data plotted using floats from a different epoch may appear shifted by approximately 719,163 days without triggering an explicit error.
Maintaining consistency requires strict adherence to the API for conversions, but uncertainty remains regarding the handling of mixed-type inputs (datetime objects and raw floats) on a single axis when the environment's epoch differs from the data's origin.
- How does the unit registry resolve conflicts when mixing datetime objects with floats computed under a legacy epoch?
- What is the recommended approach for normalizing legacy float-based date arrays to be compatible with the 1970-01-01 epoch?