改变 Python 中气泡的颜色
Changing color of bubbles in 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)
但是,我想将气泡的颜色从 purple/yellow 更改为其他颜色。请告诉我如何更改此设置?
尝试使用这些 codes.may 因为它会对您有所帮助:
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
color_continuous_scale
https://plotly.com/python/builtin-colorscales/
range_color
绑定值,因此色标不会被 肥尾 支配
在行动
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()
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)
但是,我想将气泡的颜色从 purple/yellow 更改为其他颜色。请告诉我如何更改此设置?
尝试使用这些 codes.may 因为它会对您有所帮助:
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
color_continuous_scale
https://plotly.com/python/builtin-colorscales/range_color
绑定值,因此色标不会被 肥尾 支配
在行动
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()