2
votes

enter image description hereI am unable to get figure_factory to recognize the county_choroplet module which contains create_choropleth (on line 512 I believe).

I am just using a basic example from the plotly website https://plot.ly/python/county-choropleth/

Edit: Ive tried to implement suggestions from a previous question by importing as:

from plotly.figure_factory._county_choropleth import create_choropleth

and then: 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')

But i receive the following error (in picture):

File "C:\ProgramData\Miniconda3\lib\site-packages\fiona__init__.py", line 162, in open raise IOError("no such file or directory: %r" % path)

OSError: no such file or directory: 'C:\ProgramData\Miniconda3\lib\site-packages\plotly\package_data\gz_2010_us_050_00_500k.shp'

my code

install libraries

2
Try using answer to this question. It is look similar to your problemDmitriy Kisil
So i tried to implement the changes suggested here by importing as from plotly.figure_factory._county_choropleth import create_choropleth and then ran the following: 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') however i then recieved an error code OSError: no such file or directory: 'C:\\ProgramData\\Miniconda3\\lib\\site-packages\\plotly\\package_data\\gz_2010_us_050_00_500k.shp'Clay Chester

2 Answers

1
votes

So what is did was transfer the files in C:\ProgramData\Miniconda3\pkgs\plotly-3.1.1-py36h28b3542_0\Lib\site-packages\plotly

to:

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

Then I ran the code:

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

and it worked.

0
votes

What you will get after executing this code:

# 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')

Just in my case, script return the following: Choropleth_USA