-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Implement legend entries for surface (and others like heatmap, contour) traces #2642
Comments
Surface plots (and these ribbon plots are just specialized surface plots) are like heatmap and contour maps, they generally get colorscales (controlled by |
It would also enable the user to group such traces, such that their visibility can be toggled on and off along with associated traces, even if they don't show up in the legend themselves. While the filling option for scatter3d is missing (#2352), surfaces are a viable substitute, but one would then need to use events to toggle their visibility when the visibility of their associated lines are toggled via the legend. |
That could be done using (our recently added #2581) a custom legend handler. |
I also request this feature to be added. After hours of searching, I finally found a community post that explicitly stated that Mesh3d and Surface traces do not support legends: how to name axis and show legend in mesh3d. However, this is not described anywhere in the documentation for either Mesh3d or Surface (they both show that they support the showlegend property). The use case is as described above regarding having multiple surfaces or mesh3d traces with a constant color such as when you want to use a "fill" on a scatter3d plot. |
Oof, sorry for the confusion! related: #3058 |
@alexcjohnson In the meantime, should I prune the legend-related attributes for traces that don't support them? |
I would also love to have legend entries for Surfaces. I am using Surfaces to show an image in a 3D plot (via dark wizardry), and I have several other traces in the plot. I would love to be able to only see the image and one of the traces, but if I double click on the legend entry of the trace I want to see, all other traces are disabled, including my image, and there is no way to turn it back on other than double click on the legend entry again, but that also re-enables all the other traces. Not sure if this makes as much sense to you as it does in my head! |
Is there any hack or custom legend overlay that can be done until a proper implementation is found? |
@giiyms For python, a modified version of this worked for me, though it requires a running python kernel so cannot be exported. Basically the idea is to create another trace that has a legend and link them with an event. I agree it would be nice to have a proper solution that doesn't require a running kernel. import plotly.graph_objects as go
import numpy as np
x = np.linspace(-1, 1, 10)
y = np.linspace(-1, 1, 10)
z = np.sin(x[:, None]) * np.sin(y)
f = go.FigureWidget([
go.Surface(x=x, y=y, z=z, name='c0', showscale=False), # Real data
go.Scatter3d(x=[None], y=[None], z=[None],
mode='markers', name='c1', showlegend=True), # Placeholder
go.Surface(x=x, y=y, z=-z, name='c2', showscale=False), # More real data
])
surface = f.data[0]
placeholder = f.data[1]
f.layout.hovermode = 'closest'
def update_visibility(trace, visible):
surface.visible = visible
placeholder.on_change(update_visibility, 'visible')
f |
I think all traces that can be plotted on shared subplots should honor This would actually provide a path forward for cases like #3468 ! |
Now with traces that support |
Nevermind. I found a simple way to add them. |
you mean moving Lines 1293 to 1299 in 8951847
to each trace default module? Could we simply make: // in plots.supplyTraceDefaults
var show = coerce('showlegend', Registry.traceIs(traceOut, 'showLegend'));
if(show) coerce('legendgroup'); that is the Moreover, for traces that currently have |
This would be a good idea globally if we could do it! If you have two scatter traces on top of a heatmap, say, right now the legend and colorbar overlap. |
Hi, |
Hi,
I'm using plotly.js 1.37.1 in an Angular 5 application and the showlegend attribute seems to be broken for 3D Ribbon and 3D Surface charts.
Changing the attribute and calling relayout has no effect on the chart.
The problem also appears to happen in any of the example charts in the documentation (for example this one from the documentation: Ribbon Plot example or this one: 3D Surface Plot example) Opening them in Codepen and changing the showlegend attribute has no effect on the legend.
The text was updated successfully, but these errors were encountered: