You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
plotly 6.1.2 not showing datetime for FigureWidget #5210
I debugged difference of Trace object in Plotly 5.x and 6.x. Apparently DateTimeIndex does not get converted from np.datetime64 to Python datetime.datetime.
"""Monkey-patch Plotly 6.x bug: FigureWidget showing nanoseconds instead of dates.- Workaround bug https://github.com/plotly/plotly.py/issues/5210"""fromimportlib.metadataimportversion, PackageNotFoundErrorimportdatetimefrompackaging.versionimportVersiontry:
pkg_version=version("plotly")
exceptPackageNotFoundError:
pkg_version=Noneif (pkg_versionisnotNone) andVersion(pkg_version) <=Version("6.1.2"):
importnumpyimportpandasfromplotly.graph_objsimportFiguredeffix_trace_x_axis_dates(self: Figure):
fortraceinself.data:
item=trace.x[0]
# Detect datetime64 and convert it to native Python datetime that show() can handleifisinstance(trace.x, numpy.ndarray):
ifisinstance(item, numpy.datetime64):
trace.x=pandas.Series(trace.x).dt.to_pydatetime().tolist()
# Run in the monkey patch,# so that traces are fixed when fig.show() is called_old_show=Figure.showdef_new_show(self: Figure, *args, **kwargs):
fix_trace_x_axis_dates(self)
_old_show(self, *args, **kwargs)
Figure.show=_new_show
I came across this problem in plotly 6.3.1. To stay with 6.3.1, a workaround seems to be to reduce the resolution of the datetime64 to something other than nanosecs. Eg, below changes to millisecs, but microsecs also work. Looking at other similar issues raised, use of datetime64 with nanosecond resolution seems to be a common factor.
I am a bit disappointed that this hasn't been addressed. However, based upon the feedback here (thanks @groggyjohn), I came up with a workaround that, I believe, actually gets close to fixing the underlying issue and doesn't rely upon monkeypatching Figure which seems, to me, to be unreliable given that the data can be changed/shown in many different ways:
Activity
[-]plotly 6.1.1 not showing datetime for FigureWidget[/-][+]plotly 6.1.2 not showing datetime for FigureWidget[/+]miohtama commentedon Jun 17, 2025
As a workaround you can do
.index.to_pydatetime().tolist():miohtama commentedon Jun 17, 2025
I debugged difference of Trace object in Plotly 5.x and 6.x. Apparently
DateTimeIndexdoes not get converted from np.datetime64 to Python datetime.datetime.Plotly 6.x:
Plotly 5.x:
miohtama commentedon Jun 17, 2025
Here is a monkey-patch to fix the issue:
groggyjohn commentedon Oct 23, 2025
I came across this problem in plotly 6.3.1. To stay with 6.3.1, a workaround seems to be to reduce the resolution of the datetime64 to something other than nanosecs. Eg, below changes to millisecs, but microsecs also work. Looking at other similar issues raised, use of datetime64 with nanosecond resolution seems to be a common factor.
Resulting in

mgmarino commentedon Dec 5, 2025
I am a bit disappointed that this hasn't been addressed. However, based upon the feedback here (thanks @groggyjohn), I came up with a workaround that, I believe, actually gets close to fixing the underlying issue and doesn't rely upon monkeypatching Figure which seems, to me, to be unreliable given that the data can be changed/shown in many different ways:
Of course, this code will need to be executed before anything is serialized.
emilykl commentedon Sep 2, 2026
Hi all, apologies for the belated follow-up on this one.
I believe this bug has the same root cause as #5355 and was addressed by #5415, first released in plotly.py v6.5.0 in Nov 2025.
The FigureWidget plot renders as expected in plotly.py v7.0.0:
