Search code examples
pythonmatplotlibplotlydata-visualizationplotly-express

Hide legend in plotly express (not Plotly)


I have a scatteplot I’m trying to present, with lots of symbols and colors. This makes the default legend unreadable. Is there a way to hide the legend (equivalent, or similar to showlegend=False when using traces and graph objects)?

Here’s my graphing line:

fig = px.scatter(df_revised, x='df_x', y = 'df_y', color = 'type', symbol = 'country', hover_data = ['id'], marginal_y="histogram", marginal_x="histogram")

I've seen the question mentioned here, but that is not useful, as it's changing the plotting library to plotly rather that the express version.

I have also tried fig.update_layout(showlegend=False) but that return an error AttributeError: 'ExpressFigure' object has no attribute 'update_layout'


Solution

  • With the version you have right now, fig.layout.showlegend = False should work (and continues to work with the latest version!).