Hide colorbar from px.choropleth

Hi everyone!

I’m developing an app with dash and I’m producing a lot of graphs, and some of them are choropleth but I’m having a lot of trouble trying to hide the colorbar next to the figure (see picture) , I tried showscale = False and other things but nothing seems to work… Is there any way to solve my problem?

Thanks in advance!

Hi @Cloemdz
Did you try showlegend=None ?

Hi,
Yes I already tried but got the following error message: TypeError: choropleth() got an unexpected keyword argument ‘showlegend’
Do I need to put showlegend=None somewhere else?

@Cloemdz

For any trace type that has the colorscale property, showscale=True is the default setting, and showscale=False, removes the colorbar (it is not displayed).

@empet
I tried:

fig.update_traces(showscale=False)

But it’s still there. I’m using plotly express

@adamschroeder

We have two posibilites to set colorscale:

trace= go.Choroplethmapbox(z=z,
                            locations=locations,
                            colorscale='Viridis',
                            colorbar=dict(thickness=20, ticklen=3),
                            geojson=jdata,
                            hoverinfo='all',
                            marker_line_width=0.1, marker_opacity=0.7)

In this case the showscale is set either via trace.update or fig.data[corresponding_index].update(showscale=False),
or fig.update_traces(showscale=False), when len(fig.data)=1.

  1. coloscale/colorbar are set in layout.coloraxis
trace= go.Choroplethmapbox(z=z,
                            locations=locations,
                            #colorscale='Viridis',
                            #colorbar=dict(thickness=20, ticklen=3),
                            coloraxis='coloraxis',
                            geojson=jdata,
                            hoverinfo='all',
                            marker_line_width=0.1, marker_opacity=0.7)
layout=go.Layout(width=700, height=600,
                coloraxis=dict(colorscale=mapbox,
                               colorbar=dict(thickness=20, ticklen=3))   

When the go.Figureclass was instantied
we perform this update to remove the colorscale:

fig.update_layout(coloraxis_showscale=False)
2 Likes

thank you for the detailed explanation @empet . It worked like a charm. I just corrected the spelling, taking one “s” off.

fig.update_layout(coloraxis_showscale=False)
1 Like

Thank you!!! :smile: