Black Lives Matter. Please consider donating to Black Girls Code today.

Plotly express scatter_mapbox hide legend


I am trying to the colorbar legends on the right side of my Plotly Express scatter_mapbox plot.

Here’s my code on how to make the plot.

fig = px.scatter_mapbox(df, lat="Latitude", lon="Longitude", color="Data", size="Confirmed", hover_name="State", color_continuous_scale=px.colors.cyclical.IceFire)

I’ve tried:

But the colorbar just does not want to go away. On the Plotly Express scatter mapbox documentation there’s no API to hide the colorbar.

How can I make it go away?

Hi @vitaminc



to display the layout definition. If you are seeing settings for 'coloraxis', then to remove the colorbar just make the following update:


It’s the same approach as in in the case of chropletapbox discussed here:

1 Like

That worked! Thank you so very much!!!


Since I got you here, is there a way to have hover_data not display latitude and longitude? Regardless of which column of data frame I choose, lat/lon always show up.


Thank you so much in advance for your help!


To remove displaying lon and lat for each point, type:[0].hovertemplate

and remove the settings for lon and lat

For this plotly tutorial:

we get:


With this update:[0].update(hovertemplate= 'car_hours=%{marker.size}<br>peak_hour=%{marker.color}')

lon and lat are no more displayed.


hi guys, Im not sure when this changed, but I attempted to hide the map legend using the method described by @empet fig.update_layout(coloraxis_showscale=False) but it did not work. And just to be sure I did not miss anything I also attempted the method used by @vitaminc fig.layout.update(showlegend=False) and this did work for me. There must have been a recent change.

Im using versions
plotly 4.6.0
plotly-express 0.4.1

Hi @garret

Please tell us what trace type are you defining? What I said about colorbar is still valid. Check it running this code:

import as px
df =
fig = px.scatter_mapbox(df, lat="centroid_lat", lon="centroid_lon",     color="peak_hour", size="car_hours",
                  color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=10)

Then in a notebook cell:
and you’ll get displayed:

    'colorbar': {'title': {'text': 'peak_hour'}},
    'colorscale': [[0.0, '#000000'], [0.0625, '#001f4d'], [0.125, '#003786'],
                   [0.1875, '#0e58a8'], [0.25, '#217eb8'], [0.3125, '#30a4ca'],
                   [0.375, '#54c8df'], [0.4375, '#9be4ef'], [0.5, '#e1e9d1'],
                   [0.5625, '#f3d573'], [0.625, '#e7b000'], [0.6875, '#da8200'],
                   [0.75, '#c65400'], [0.8125, '#ac2301'], [0.875, '#820000'],
                   [0.9375, '#4c0000'], [1.0, '#000000']]

Now this update:


removes the colorbar. (I have Plotly 4.6.0, too)

It seems that you are not making distinction between legend and colorbar The colorbar is always associated when you are setting a colorscale, and the showscale=True (its default value is True), and almost sure your comment above is referring to a trace type that doesn’t colormap a list of values to a colorscale.

Hi @empet,

I see now thank you for the clarification.