我在:https://plotly.com/python/county-choropleth/上看到了下面的示例代码,并根据我的Jupiter Notebook进行了调整,它工作了,但现在出了问题,我收到的错误指示缺少包/模块,我对python有点陌生,尝试了许多不起作用的东西,请帮助我,我错过了什么包/模块?
! pip install plotly-geo == 1.0.0! pip install geopandas == 0.3.0! pip install pyshp == 1.2.10! pip install shapely == 1.6.3
将plotly. figure_factory导入为ff
import numpy as np import pandas pd
© 2019 www.githubusercontent.com.cn版权所有并保留所有权利pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/minoritymajority.csv') df_sample_r = df_sample[df_sample['STNAME'] == 'Florida']
values = df_sample_r ['TOT_POP']. tolist()fips = df_sample_r ['FIPS ']. tolist()
endpts = list(np. mgrid [min(values):max(values):4j])colorscale =["#030512","#1d1d3b","#323268","#3d4b94","#3e6ab0","#4989bc","#60a7c7","#85c5d3","#b7e0e4","#eafcfd"] fig = ff. create_choropleth(fips = fips,values = values,scope = ['Florida '],show_state_data = True,colorscale = colorscale,binning_endpoints = endpts,round_legend_values = True,plot_bgcolor ='rgb(229,229,229)',paper_bgcolor ='rgb(229,229,229)',legend_title ='Population by County',county_outline ='rgb(255,255,255)','width':0.5},exponent_format = True,)fig. layout. template = None www.example.com()fig.show()
1条答案
按热度按时间mnemlml81#
据我所知,在plotly community中也有类似的问题,但没有解决方案。我建议使用geojson文件的替代解决方案。从参考中获取US geojson文件,并将其与佛罗里达的数据相结合。使用此组合的地理数据框架来可视化人口数据。将目标元素更改为适合您目的的数据。