Cannot plot a plotly chart from pandas dataframe with DateTimeIndex #517
-
Hi. As in the title, I have a problem with plotting the plotly chart from pandas DataFrame with the DateTimeIndex.
This error doesn't show when I use matplotlib pyplot instead of plotly, chart shows correctly with the DateTimeIndex on the x-axis. Packages versions:
Kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Can you provide some minimum example code to reproduce the problem? That would help a lot. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Ok, I boiled it down to this: from io import StringIO
import matplotlib.pyplot as plt
import pandas as pd
from plotly import graph_objects as go
from nicegui import ui
csv = '''Date;Value
01.01.2018 00:00;100.0
01.01.2018 00:10;120.0
01.01.2018 00:20;110.0
'''
df = pd.read_csv(StringIO(csv), sep=';')
df = df.set_index(pd.to_datetime(df['Date'], format=r'%d.%m.%Y %H:%M')) # this line breaks the plotly chart
chart = go.Figure(go.Scatter(x=df.index, y=df['Value']))
ui.plotly(chart)
with ui.pyplot():
plt.plot(df.index, df['Value'], '-') # the pyplot still works
ui.run() Apparently go.Scatter(x=df.index.to_pydatetime().tolist(), ...) With @rbeeli Do you have experience with orjson and |
Beta Was this translation helpful? Give feedback.
Ok, I boiled it down to this:
Apparently
df.index
is of typeDatetimeIndex
, which is not JSON-serializable, even with orjson.But I found the…