使用 Geopandas 和 county-choropleth 模块

Using Geopandas and the county-choropleth module

我无法让 figure_factory 识别包含 create_choropleth 的 county_choroplet 模块(我相信在第 512 行)。

我只是使用 plotly 网站上的一个基本示例 https://plot.ly/python/county-choropleth/

编辑:我试图通过导入为

来实施之前的建议
from plotly.figure_factory._county_choropleth import create_choropleth

然后: fig = create_choropleth(fips=fips, values=values) py.ploy(fig, filename='basic-choropleth') py.iplot(fig, filename='choropleth of some cali counties - full usa scope')

但我收到以下错误(如图):

文件 "C:\ProgramData\Miniconda3\lib\site-packages\fiona__init__.py",第 162 行,打开 提高 IOError("no such file or directory: %r" % 路径)

OSError: 没有这样的文件或目录: 'C:\ProgramData\Miniconda3\lib\site-packages\plotly\package_data\gz_2010_us_050_00_500k.shp'

执行这段代码后你会得到什么:

# import necessary libraries
import geopandas
import shapely
import shapefile
import plotly
from plotly.figure_factory._county_choropleth import create_choropleth

# Check your plotly version
print(plotly.__version__, geopandas.__version__,shapely.__version__,shapefile.__version__)
# Data
fips = ['06021','06023','06027',
        '06029','06033','06059',
        '06047','06049','06051',
        '06055','06061']
values = range(len(fips))
# Create fig
fig = create_choropleth(fips=fips, values=values)
# Plot in offline mode and save plot in your Python script folder
plotly.offline.plot(fig, filename='choropleth_usa.html')

就我而言,脚本 return 以下内容:

所以所做的就是运行传送C:\ProgramData\Miniconda3\pkgs\plotly-3.1.1-py36h28b3542_0\Lib\site-packages\plotly

中的文件

至:

C:\ProgramData\Miniconda3\Lib\site-packages\plotly

然后我运行代码:

import plotly.plotly as py
from plotly.figure_factory._county_choropleth import create_choropleth

py.sign_in('chessybo', 'XXXXXXXXXXX')

fips = ['06021', '06023', '06027',
        '06029', '06033', '06059',
        '06047', '06049', '06051',
        '06055', '06061']
values = range(len(fips))

#fig = ff.create_choropleth(fips=fips, values=values)
fig = create_choropleth(fips=fips, values=values)
#py.plotly(fig, filename='basic-choropleth')
py.plot(fig, filename='choropleth of some cali counties - full usa scope')

它奏效了。