Hello,
it would be very nice to have the possibilty to set the z-ordering priority of traces in plotly. I think the way matplotlib handles it is pretty handy:
Veeeery useful. Right now I am strugling to have a marker to appear on top of a bunch of line plots and it is very annoying.
By the way, the hack I found to overcome this problem right now is to store the trace I want to add on TOP in a globalvariable (on can think of a list if one have multiple trace to add in a certain ordering) and then, just before rendering the figure, I had the trace to the figure. Then the last added trace appears on top of all other traces.
I am encountering the same issue. I would like to add several lines on top of scatter plot generated by px.scatter() .I tried to reorder the traces by doing fig.data = fig.data[::-1] but it only changes the order shown in legend, I still have not been able to add lines on top of points after trying almost all the tricks online, which is a bit frustrating..
it would be super helpful if plotly can support something like zorder
Another use case for this feature is related to legend ordering. Currently, if you use the order of traces to specify the legend ordering, we cannot specify a z order independently. Since legend order is either None (i.e. insertion order) or alphabetical order, it is impossible to set an arbitrary order of legend items and at the same time set and arbitrary zorder of traces.
Has there been any movement to try to implement this?
A few notes on this:
I should add that fig.data = fig.data[::-1] does work for me:
import plotly.express as px
import plotly.graph_objects as go
fig = px.scatter(x=[1,2,3,4], y=[1,2,3,4], size=[1,2,3,4], color=["a","a","b","b"])
fig.add_trace(go.Scatter(x=[1,2,3,4], y=[1,2,3,4], mode="lines", line_color="black"))
fig.data = fig.data[::-1]
fig.show()
as does reordering fig.data like this:
import plotly.express as px
import plotly.graph_objects as go
fig = px.scatter(x=[1,2,3,4], y=[1,2,3,4], size=[1,2,3,4], color=["a","a","b","b"])
fig.add_trace(go.Scatter(x=[1,2,3,4], y=[1,2,3,4], mode="lines", line_color="black"))
fig.data = (fig.data[1],fig.data[2],fig.data[0])
fig.show()
Any news on this? This would be a great feature!
Most helpful comment
Any news on this? This would be a great feature!