US county choropleth map

I’m trying to recreate the code from https://plot.ly/python/county-choropleth/

at first I was having a similar issue to @drissguessous USA County Choropleth Maps in Python but after using conda prompt to install geopandas (it’s a lot easier) that part was solved.

However, I still cannot recreate the maps.
Now, I get an error
OSError: no such file or directory: ‘C:\Users\sanchez\AppData\Local\Continuum\anaconda3\lib\site-packages\plotly\figure_factor/package_data/gz_2010_us_050_00_500k.shp’

after a quick search I saw that the issue was solved (PR #940 and #943) and that the shapefiles are shipped with the 2.4.1

I am not sure what it is that I am doing wrong. or how to solve it.
I already uninstalled plotly and re-installed 2.4.1
Is this an issue that will be solved in 2.4.2 and i should just wait? if not, what can I do right now?
-Chekos

Hello,

As far as I am aware, 2.4.1 should be working just fine and contain all the required files. This may be a bug with Anaconda.

In your error message:

‘C:\Users\sanchez\AppData\Local\Continuum\anaconda3\lib\site-packages\plotly\figure_factor/package_data/gz_2010_us_050_00_500k.shp’

Is this exactly the error message you received? Did it say figure_factor (like you have) or figure_factory in the path?

If it is the former then I suspect the folder name was changed accidentally after installation. The code used to search for the needed shapefiles relies on having a directory called figure_factory in the plotly folder. Let me know if this is the case.

1 Like

Yes, that’s exactly what it says.
Here’s a copy of the whole message.

OSError Traceback (most recent call last)
in ()
6 legend_title=‘Population by County’,
7 county_outline={‘color’: ‘rgb(255,255,255)’, ‘width’: 0.5},
----> 8 exponent_format=True,
9 )
10 py.iplot(fig, filename=‘choropleth_CA’)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\plotly\figure_factory_county_choropleth.py in create_choropleth(fips, values, scope, binning_endpoints, colorscale, order, simplify_county, simplify_state, asp, offline_mode, show_hover, show_state_data, state_outline, county_outline, centroid_marker, round_legend_values, exponent_format, legend_title, **layout_options)
572
573 df, df_state = _create_us_counties_df(st_to_state_name_dict,
–> 574 state_to_st_dict)
575
576 fips_polygon_map = dict(

~\AppData\Local\Continuum\anaconda3\lib\site-packages\plotly\figure_factory_county_choropleth.py in _create_us_counties_df(st_to_state_name_dict, state_to_st_dict)
29 shape_pre2010 = 'gz_2010_us_050_00_500k.shp’
30 shape_pre2010 = abs_package_data_dir_path + shape_pre2010
—> 31 df_shape_pre2010 = gp.read_file(shape_pre2010)
32 df_shape_pre2010[‘FIPS’] = (df_shape_pre2010[‘STATE’] +
33 df_shape_pre2010[‘COUNTY’])

~\AppData\Local\Continuum\anaconda3\lib\site-packages\geopandas\io\file.py in read_file(filename, **kwargs)
17 “”"
18 bbox = kwargs.pop(‘bbox’, None)
—> 19 with fiona.open(filename, **kwargs) as f:
20 crs = f.crs
21 if bbox is not None:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\fiona_init_.py in open(path, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt)
160 raise IOError(“no such archive file: %r” % archive)
161 elif path != ‘-’ and not os.path.exists(path):
–> 162 raise IOError(“no such file or directory: %r” % path)
163 c = Collection(path, mode, driver=driver, encoding=encoding,
164 layer=layer, vsi=vsi, archive=archive,

OSError: no such file or directory: ‘C:\Users\sanchez\AppData\Local\Continuum\anaconda3\lib\site-packages\plotly\figure_factor/package_data/gz_2010_us_050_00_500k.shp’

if that’s the case, do I just need to change the name? that should solve it, right?

EDIT:
I followed the path and it seems like I do have the folder named “figure_factory”

I’m having the exact same problem.

I have a similar problem. This is what i get,
OSError Traceback (most recent call last)
in ()
1 fig = ff.create_choropleth(
2 fips = minoritydata[“FIPS”],
----> 3 values = minoritydata[“TOT_POP”])

~\Anaconda3\lib\site-packages\plotly\figure_factory_county_choropleth.py in create_choropleth(fips, values, scope, binning_endpoints, colorscale, order, simplify_county, simplify_state, asp, offline_mode, show_hover, show_state_data, state_outline, county_outline, centroid_marker, round_legend_values, exponent_format, legend_title, **layout_options)
568
569 df, df_state = _create_us_counties_df(st_to_state_name_dict,
–> 570 state_to_st_dict)
571
572 fips_polygon_map = dict(

~\Anaconda3\lib\site-packages\plotly\figure_factory_county_choropleth.py in _create_us_counties_df(st_to_state_name_dict, state_to_st_dict)
24 shape_pre2010 = 'gz_2010_us_050_00_500k/gz_2010_us_050_00_500k.shp’
25 shape_pre2010 = data_url + shape_pre2010
—> 26 df_shape_pre2010 = gp.read_file(shape_pre2010)
27 df_shape_pre2010[‘FIPS’] = (df_shape_pre2010[‘STATE’] +
28 df_shape_pre2010[‘COUNTY’])

~\Anaconda3\lib\site-packages\geopandas\io\file.py in read_file(filename, **kwargs)
17 “”"
18 bbox = kwargs.pop(‘bbox’, None)
—> 19 with fiona.open(filename, **kwargs) as f:
20 crs = f.crs
21 if bbox is not None:

~\Anaconda3\lib\site-packages\fiona_init_.py in open(path, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt)
160 raise IOError(“no such archive file: %r” % archive)
161 elif path != ‘-’ and not os.path.exists(path):
–> 162 raise IOError(“no such file or directory: %r” % path)
163 c = Collection(path, mode, driver=driver, encoding=encoding,
164 layer=layer, vsi=vsi, archive=archive,

OSError: no such file or directory: ‘plotly/package_data/data/gz_2010_us_050_00_500k/gz_2010_us_050_00_500k.shp’

Has anybody found a solution ?

Okay, SO i reinstalled plotly and then i got the same error as @chekos.
So i opened up the plotly directory but there was no figure_factor folder in there.
Create a new folder “figure_factor” in plotly directory and copy the “package_data” folder into this folder.

That worked for me.

So it was a typo by Plotly?

Ran into the exact problem. Tried your fix, and it worked perfectly.

Thanks a million!!!

I just updated to plotly 2.5.0 and the problem is fixed.
Thanks @pranu_kvs for the fix meanwhile!

Still and issue in 2.5.0. I have to rename the figure_factory file to figure_factor and then copy in the package_data folder.

The update worked in my macbook but not in my work computer (Windows). I wonder if that has anything to do with it.

There is a PR open now to resolve this issue. Thank you for everyone’s patience.

Fixed! Checkout the latest version of Plotly (2.5.1) to get the fix to the choropleth FF for Windows.
Check the CHANGELOG for more information.

1 Like

Everything works great now. Thanks!