plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.04k stars 2.54k forks source link

Property `zorder` cannot be updated on Scattergl traces. #4746

Open PhilippVerpoort opened 3 weeks ago

PhilippVerpoort commented 3 weeks ago

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.

gvwilson commented 3 weeks ago

possibly related to https://github.com/plotly/plotly.js/issues/7070 ? cc @archmoj