Description
Updating the zorder
property on existing traces only works for go.Scatter
traces but not for go.Scattergl
traces. The same command may therefore fail or succeed, simply depending on the number of traces.
This works as expected:
import plotly.express as px
df_small = pd.DataFrame(dict(x=range(5), y=range(5)))
px.line(df_small).update_traces(zorder=-1)
This returns error Bad property path: zorder
:
import plotly.express as px
import pandas as pd
df_large = pd.concat([
df_small.assign(y=lambda df: df['y'] + n/1000, n=n)
for n in range(1000)
])
px.line(df_large, color='n').update_traces(zorder=-1) # calling update_traces raises ValueError with message 'Bad property path: zorder'
The difference between the two is that the first creates simple go.Scatter
traces, whereas the second dataframe is so large that plotly tries to use go.Scattergl
traces. Those however do not accept the zorder
property (see also the documentation of go.Scattergl
).
If for some reason the zorder
cannot be implemented on go.Scattergl
graph objects, then plotly should just not provide it and instead warn the user. The same code resulting in behaviour depending on the size of the dataframe passed is really unexpected and can be tedious to debug.
This issue may also be linked to #1514.