无法让地图出现在 Python 数据可视化中
Can't get map to appear in Python Data Visualization
我正在尝试可视化 Python 内的美国 COVID-19 数据。目前我有一个 CSV 文件,其中包含我所有导入的数据,其中包含案例编号、经度、纬度等。目前我的代码如下:
df=pd.read_csv
fig=px.scatter_mapbox(df,lat='Lat', lon='Long', hover_name='Province_State', size='Confirmed',mapbox_style='open-streetmap',template='plotly_dark')
fig.write_html("Time_series_county_JH.html")
fig.show()
但是,当我 运行 代码时,我只得到一个黑框,右边有图例
如果有人可以帮助我如何让实际的地图出现而不仅仅是黑色输出,那就太好了。我是 Python 的新手,如有任何帮助,我们将不胜感激。
我认为您在使用 plotly 渲染图像时遇到了问题。
您可以如下设置 plotly 图像的渲染器:
import plotly.io as pio
pio.renderers.default = "colab"
并更改代码中的以下行,如下所示:
pio.show(fig)
如果图还是黑的,那就是mapbox_style
的问题。改成相关要求。
mapbox_style='carto-darkmatter'
整体:
df=pd.read_csv("/content/COVID-19_Cases_US.csv")
fig=px.scatter_mapbox(df, lat='Lat', lon='Long_', hover_name='Province_State', size='Confirmed',color='Confirmed',mapbox_style='carto-darkmatter',template='plotly_dark',zoom=0, size_max=70)
fig.write_html("Time_series_county_JH.html")
pio.show()
结果:
更新:
对于 mapbox_style
= 'open-street-map' 和代码:
df=pd.read_csv("/content/COVID-19_Cases_US.csv")
fig=px.scatter_mapbox(df, lat='Lat', lon='Long_', hover_name='Province_State', size='Confirmed',color='Confirmed',mapbox_style='open-street-map',template='plotly_dark',zoom=4, size_max=70)
fig.write_html("Time_series_county_JH.html")
fig.show()
结果如下:
我正在尝试可视化 Python 内的美国 COVID-19 数据。目前我有一个 CSV 文件,其中包含我所有导入的数据,其中包含案例编号、经度、纬度等。目前我的代码如下:
df=pd.read_csv
fig=px.scatter_mapbox(df,lat='Lat', lon='Long', hover_name='Province_State', size='Confirmed',mapbox_style='open-streetmap',template='plotly_dark')
fig.write_html("Time_series_county_JH.html")
fig.show()
但是,当我 运行 代码时,我只得到一个黑框,右边有图例
如果有人可以帮助我如何让实际的地图出现而不仅仅是黑色输出,那就太好了。我是 Python 的新手,如有任何帮助,我们将不胜感激。
我认为您在使用 plotly 渲染图像时遇到了问题。
您可以如下设置 plotly 图像的渲染器:
import plotly.io as pio
pio.renderers.default = "colab"
并更改代码中的以下行,如下所示:
pio.show(fig)
如果图还是黑的,那就是mapbox_style
的问题。改成相关要求。
mapbox_style='carto-darkmatter'
整体:
df=pd.read_csv("/content/COVID-19_Cases_US.csv")
fig=px.scatter_mapbox(df, lat='Lat', lon='Long_', hover_name='Province_State', size='Confirmed',color='Confirmed',mapbox_style='carto-darkmatter',template='plotly_dark',zoom=0, size_max=70)
fig.write_html("Time_series_county_JH.html")
pio.show()
结果:
更新:
对于 mapbox_style
= 'open-street-map' 和代码:
df=pd.read_csv("/content/COVID-19_Cases_US.csv")
fig=px.scatter_mapbox(df, lat='Lat', lon='Long_', hover_name='Province_State', size='Confirmed',color='Confirmed',mapbox_style='open-street-map',template='plotly_dark',zoom=4, size_max=70)
fig.write_html("Time_series_county_JH.html")
fig.show()
结果如下: