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)
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.