24

I am creating a bar graph with something like this:

px.bar(df, x=x, y=y, color=c,
       title=params['title'], 
       hover_data=hover_data)

When c != None the graph produces either a legend or a colorbar. How can I remove either of them?

Soerendip
  • 7,684
  • 15
  • 61
  • 128

7 Answers7

26

For the legend, you can use either fig.update_traces(showlegend=False) or fig.update(layout_showlegend=False).

For the colorbar, you can only use fig.update(layout_coloraxis_showscale=False). On normal plotly figures, you could also do fig.update_traces(marker_showscale=False), but it does not work for plotly express because of how facetted traces need to share the same colorscale .

joelostblom
  • 43,590
  • 17
  • 150
  • 159
  • ```fig.update_traces(marker_showscale=False)``` does work for me in Plotly express (I'm on using Plotly version 3.10.0) – Polina Sklyarevsky Nov 05 '19 at 12:50
  • Thanks @PolinaSklyarevsky, I have only been using plotly since v4 so I am not sure how it behaved before that. – joelostblom Nov 05 '19 at 16:57
  • In Plotly 5.14.0, fig.update(layout_coloraxis_showscale=False) works but fig.update_traces(marker_showscale=False) does not, at least for my use case. – KBurchfiel Jun 13 '23 at 01:36
22

In v5.1.0, this works for me:

fig.update_coloraxes(showscale=False)
Before After
Bar chart with gradient color bar on right side Only bar chart
aheze
  • 24,434
  • 8
  • 68
  • 125
  • 1
    This is just a side note for anyone reaching this answer trying to remove the colorbar for a `go.Heatmap`, (i.e. using graph_objects, not plotly express). You must first specify a coloraxis when making the Heatmap trace e.g. `go.Heatmap(..., coloraxis='coloraxis')`. Alternatively, `fig.update_traces(showscale=False)` will do the trick. – Tim Child Dec 07 '22 at 20:49
20

This worked for me!

fig.update_traces(showscale=False)
Kyle Pastor
  • 489
  • 4
  • 8
8

fig.update_layout(coloraxis_showscale=False) worked for me in plotly 5.6.0

asquare
  • 203
  • 2
  • 7
4

To hide the colorbar with plotly express using Plotly V4:

fig.update_traces(
    marker_coloraxis=None
)
2

In addition to the options already presented, fig.update_layout(coloraxis_showscale=False) works, too.

I find I often use fit.update_layout() already, so it's nice to be able to get rid of the colorbar in the same method call.

jeffhale
  • 3,759
  • 7
  • 40
  • 56
0

Adding

fig.update_layout(showlegend=False)

worked for me in plotly version 5.15

Pablo Cánovas
  • 151
  • 1
  • 6