Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Description
Bug summary
When the time series to plot has a day light saving change and the time zone of data changes, the ticker labels formatted incorrectly. It seems to format time zone part instead of the correct base, in this example the day.
Code for reproduction
importdatetimeimportmatplotlib.pyplotaspltimportnumpyasnpimportmatplotlib.datesasmdatesfromzoneinfoimportZoneInfobase=datetime.datetime(2005,2,1)dates= [base+datetime.timedelta(hours=(2*i))foriinrange(732)]N=len(dates)np.random.seed(19680801)y=np.cumsum(np.random.randn(N))fig,axs=plt.subplots(3,1,layout='constrained',figsize=(6,6))lims= [(np.datetime64('2024-10-27'),np.datetime64('2024-11-10')), (np.datetime64('2024-11-11'),np.datetime64('2024-11-22')), (np.datetime64('2005-02-03 11:00'),np.datetime64('2005-02-04 13:20')) ]fig,axs=plt.subplots(3,1,layout='constrained',figsize=(6,6))fornn,axinenumerate(axs):# locator = mdates.AutoDateLocator()locator=mdates.AutoDateLocator(tz=ZoneInfo("America/Los_Angeles"))formatter=mdates.ConciseDateFormatter(locator)formatter.formats= ['%y',# ticks are mostly years'%b',# ticks are mostly months'%d',# ticks are mostly days'%H:%M',# hrs'%H:%M',# min'%S.%f', ]# secs# these are mostly just the level above...formatter.zero_formats= ['']+formatter.formats[:-1]# ...except for ticks that are mostly hours, then it is nice to have# month-day:formatter.zero_formats[3]='%d-%b'formatter.offset_formats= ['','%Y','%b %Y','%d %b %Y','%d %b %Y','%d %b %Y %H:%M', ]ax.xaxis.set_major_locator(locator)ax.xaxis.set_major_formatter(formatter)ax.plot(dates,y)ax.set_xlim(lims[nn])axs[0].set_title('Concise Date Formatter')plt.show()
Actual outcome

Expected outcome
2nd graph of the same image shows the expected tick labels in the graph.
Additional information
No response
Operating system
No response
Matplotlib Version
3.9.2
Matplotlib Backend
macosx
Python version
Python 3.11.6
Jupyter version
No response
Installation
pip