-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
plotly 6.1.2 not showing datetime for FigureWidget #5210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As a workaround you can do index = df.index.to_pydatetime().tolist()
# Price chart (top subplot)
fig.add_trace({
"x": index,
"y": df["mark_price"], |
I debugged difference of Trace object in Plotly 5.x and 6.x. Apparently Plotly 6.x:
Plotly 5.x:
|
Here is a monkey-patch to fix the issue: """Monkey-patch Plotly 6.x bug: FigureWidget showing nanoseconds instead of dates.
- Workaround bug https://github.com/plotly/plotly.py/issues/5210
"""
from importlib.metadata import version, PackageNotFoundError
import datetime
from packaging.version import Version
try:
pkg_version = version("plotly")
except PackageNotFoundError:
pkg_version = None
if (pkg_version is not None) and Version(pkg_version) <= Version("6.1.2"):
import numpy
import pandas
from plotly.graph_objs import Figure
def fix_trace_x_axis_dates(self: Figure):
for trace in self.data:
item = trace.x[0]
# Detect datetime64 and convert it to native Python datetime that show() can handle
if isinstance(trace.x, numpy.ndarray):
if isinstance(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.show
def _new_show(self: Figure, *args, **kwargs):
fix_trace_x_axis_dates(self)
_old_show(self, *args, **kwargs)
Figure.show = _new_show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The FigureWidget seems to be broken in plotly 6.0 when showing datetime types.
Reproduced using the example here
displays correctly with datetime:
With FigureWidget:
shows the nanosecond ints:
This was run in VSCode (1.100.2) and also jupyterlab/server (lab == 4.4.3, jupyter-server == 2.16.0)
Seems similar to #5101.
The text was updated successfully, but these errors were encountered: