在Python中更改气泡的颜色

2024-06-02 08:47:20 发布

您现在位置:Python中文网/ 问答频道 /正文

Python新手,我使用以下代码构建了一个可视化:

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)

但是,我想将气泡的颜色从紫色/黄色更改为其他颜色。你能告诉我怎么改变这个吗


2条回答

尝试使用这些代码。它可能会帮助您: 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))

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

正在运行


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

相关问题 更多 >