Plotly: How to export only active legend when exporting plotly graph as png?

Viewed 266

I have a plotly graph with more than 80 individual traces: Plotly png export of all traces

Now I want to export a png with only a few active traces like this: This is a screenshot of what I want it to look like

But when I export the image with the plotly camera icon it shows the top of the legend and not the legend of the active traces: Actual export with plotly

My question is, is there a way to tell plotly to export the graph with only the active trace legends visible?

1 Answers

This is pretty interesting. If you use the approch described here, and run

fig.write_image("yourfile.png")

...then you'll get the original fig object with all traces included. Even after subsetting the series through the legend.

But if you use the camera icon on the toolbar, then you'll get the edited version as a .png file.

enter image description here

Related