简体   繁体   中英

How to hide the colorbar and legend in plotly express bar graph?

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?

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 .

This worked for me!

fig.update_traces(showscale=False)

In v5.1.0 , this works for me:

fig.update_coloraxes(showscale=False)
Before After
右侧带有渐变颜色条的条形图 只有条形图

To hide the colorbar with plotly express using Plotly V4:

fig.update_traces(
    marker_coloraxis=None
)

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM