-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feature request: z-ordering parameter for traces #2345
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
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 it would be super helpful if plotly can support something like |
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 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 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! |
+1, would love to be able to draw scatter traces BEHIND candlesticks for example. When trying to use hover label to inspect individual candles, other lines on top prevent label from showing. |
Seems this trick doesn't work when there is too much data. Example: import plotly.express as px
import plotly.graph_objects as go
import numpy as np
df = np.random.randint(0,100,size=(10000, 2))
color_df = np.random.randint(0,4,size=(10000, 1)).T[0]
centers = np.random.randint(0,100,size=(7, 2))
fig = px.scatter(x=df[:, 0], y=df[:, 1], color=color_df)
fig.add_scatter(
x=centers[:, 0],
y=centers[:, 1],
marker=dict(size=20, color="LightSeaGreen"),
name="Centers",
mode="markers",
)
fig.data = (fig.data[1], fig.data[0])
fig.show() I tried removing the optional parameters and use only X,Y but it keeps putting the centers below the data. |
I'm having a similar issue with a Candlestick trace always rendering in the BG, but in my case, I see the the legend re-ordered, but the graph maintains the old |
This does allow you to rearrange the order of the traces, but it rearranges it both in the legend and in the plot itself. The layering of the traces still seems to be inextricably linked to the order of the legend, unless there's something I'm missing. Often, I want less important traces to be at the bottom of the legend AND at the bottom layer on the plot. I don't see a way to do this currently. +1 for z-ordering parameter suggestion :) (BTW, I love plotly and use it all the time. Thanks for maintaining such an awesome library!) |
@set92, @ptim just a quick FYI as I got a similar problem (with "too much" data) and got it working following your lead. The hint was in #2345 (comment), i.e. the ordering is done per type. In your example in #2345 (comment) the import plotly.express as px
import plotly.graph_objects as go
import numpy as np
df = np.random.randint(0, 100, size=(10000, 2))
color_df = np.random.randint(0, 4, size=(10000, 1)).T[0]
centers = np.random.randint(0, 100, size=(7, 2))
fig = px.scatter(x=df[:, 0], y=df[:, 1], color=color_df)
fig.add_trace(
go.Scattergl(
x=centers[:, 0],
y=centers[:, 1],
marker=dict(size=20, color="LightSeaGreen"),
name="Centers",
mode="markers",
)
)
fig.show() |
Please note that the idea of controlling the legend order is tracked in #2345, and is in principle distinct from the drawing order. |
Update on legend ordering independently of trace ordering in |
@nicolaskruchten Thank you! Is it possible also to specify this for the shapes? I would like to keep sibling shapes in the same z-order. Is it affecting traces z-order or only legends order in the legends panel? |
|
@nicolaskruchten Basically, my problem was that when you have subplots it's hard to control order of the legends sorted.
Expected legend: But in reality it was taken grouped from subplots. This sorting problem is solved by legendrank. But also sorting collerates with order for me: Actually to achieve the top most (legend on right) I have reverted order of the traces before appending them and than reverted back by the plotly property 'revert legends order'. Now I can append in any order to control z and rank legends to keep order. |
Related to this, not having a z-order for a ridgeline plot caused me some trouble. I wanted the bottom traces to be drawn on top. But it seems that both the stacking order for violin plots and the (implicit) z-order are both bound to the See my comment on the ridgeline plots issue: plotly/plotly_express#25 (comment) See my post in the community forum: https://community.plotly.com/t/ridgeline-joy-plot-without-transparency/55028?u=maegul |
And it works for me also. So pleased that fleimgruber found and offered the work around that, after 'wasting' a day trying to find a solution, I signed up just to say 'Thank You, fleimgruber'. |
For the |
Would be a very nice and useful feature |
Why is it still not implemented after 3 years?! |
Nobody is being paid to do this. it's not happening unless you or someone else decides to donate their time. |
Does someone fancy donating their time to this issue? - for the forwarding and advancement of humankind |
Up! This feature would be ace to have! |
After reading this issue, plotly/plotly.py#2345 (comment) We needed to convert the traces, which were Scatter() objects, into Scattergl() objects as they have different drawing priorities. In the future, we should change the cache to be of ScatterGL objects instead of Scatter. This is a temporary fix
Life changing feature, would love to see it implemented in the future! |
push push |
Same here, this would be useful! |
imperative feature. It should also be possible to alter the order in the rendered plot, by dragging and dropping the key items into the desired order. |
Want to note, given there is so much excitement about this feature in this thread: Members of the Plotly team are currently working on this feature in |
I'm happy to announce that this feature is now available from version 5.21.0 for all SVG based cartesian traces. Please see the example below: import plotly.graph_objects as go
fig = go.Figure(
go.Bar(
x=[0, 1, 2],
y=[1, 2, 3]
)
)
fig.add_trace(
go.Scatter(
x=[0, 1, 2],
y=[3, 2, 1],
zorder=-2
)
)
fig.show() |
Awesome! Thanks so much to all the developers. |
Really awesome! This helps a lot. However, it is still not supported for annotations It would be really useful to set a watermark or "disclaimer message", for instance. |
It's still not supported for scattergl traces in plotly.js |
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.
The text was updated successfully, but these errors were encountered: