James Black
James Black

Reputation: 17

Changing color of bubbles in Python

New to Python and I have built a visualization using the following code:

df=pd.read_csv

fig=px.scatter_mapbox(df, lat='Latitude', 
                      lon='Longitude', 
                      hover_name='Combined_Key',
                      size='Confirmed',
                      mapbox_style='stamen-terrain',
                      zoom=10, 
                      size_max=100)

However, I want to change the color of the bubbles from purple/yellow to an alternative color. Please can you let me know how I can change this?

Upvotes: 0

Views: 371

Answers (2)

Rob Raymond
Rob Raymond

Reputation: 31166

https://plotly.github.io/plotly.py-docs/generated/plotly.express.scatter_mapbox.html

in action


df = pd.read_csv('http://coronavirus-resources.esri.com/datasets/628578697fb24d8ea4c32fa0c5ae1843_0.csv?outSR={"latestWkid":4326,"wkid":4326}')
# df=pd.read_csv("/content/COVID-19_Cases_US.csv")

fig=px.scatter_mapbox(df, lat='Lat', 
                      lon='Long_', 
                      hover_name='Combined_Key',
                      size='Confirmed',
                      color='Deaths',
                      mapbox_style='stamen-terrain',
                      color_continuous_scale="ylorrd",
                      range_color=[df["Deaths"].quantile(.5),df["Deaths"].quantile(.95)],
                      zoom=4, 
                      size_max=40)

fig.update_layout(
    mapbox_style="white-bg",
    mapbox_layers=[
        {
            "below": 'traces',
            "sourcetype": "raster",
            "sourceattribution": "United States Geological Survey",
            "source": [
                "https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}"
            ]
        }
      ])
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

Upvotes: 2

Nikhil Jothi Prakash
Nikhil Jothi Prakash

Reputation: 11

try with these codes.may be it will help you: px.scatter_mapbox(df, lat='Lat',lon='Long_',hover_name='Combined_Key',size='Confirmed', color='Deaths',mapbox_style='stamen-terrain',zoom=4,size_max=40,cmap="Blues",alpha=0.4,edgecolors="grey",linewidth=2))

Upvotes: 0

Related Questions