Since upgrading to plotly 4 and attempting to use the chart_studio functionality, I have been encountering some very strange behavior when trying to make a county choropleth map. I can get the map to work when I install plotly without chart_studio, but not when I install it with chart_studio. The following code does not work:
In Anaconda prompt (as far as I can tell, I am following the instructions from the getting started page exactly):
conda create -n choropleth-test python=3.7
conda activate choropleth-test
conda install -c plotly plotly=4.1.0
conda install "notebook>=5.3" "ipywidgets>=7.2"
conda install -c plotly plotly-geo=1.0.0
conda install -c plotly chart-studio=1.0.0
conda install geopandas
In jupyter notebook (this is the example from the county choropleth page):
import chart_studio.plotly as py
import plotly.figure_factory as ff
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.layout.template = None
py.plot(fig,filename = 'choropleth-test', auto_open=True)
I then get the following error message:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-30f4890102bf> in <module>
8 values = range(len(fips))
9
---> 10 fig = ff.create_choropleth(fips=fips, values=values)
11 fig.layout.template = None
12 py.plot(fig,filename = 'choropleth-test', auto_open=True)
~\AppData\Local\Continuum\miniconda3\envs\choropleth-test\lib\site-packages\plotly\figure_factory\_county_choropleth.py in create_choropleth(fips, values, scope, binning_endpoints, colorscale, order, simplify_county, simplify_state, asp, show_hover, show_state_data, state_outline, county_outline, centroid_marker, round_legend_values, exponent_format, legend_title, **layout_options)
627 if not gp or not shapefile or not shapely:
628 raise ImportError(
--> 629 "geopandas, pyshp and shapely must be installed for this figure "
630 "factory.\n\nRun the following commands to install the correct "
631 "versions of the following modules:\n\n"
ImportError: geopandas, pyshp and shapely must be installed for this figure factory.
Run the following commands to install the correct versions of the following modules:
$ pip install geopandas==0.3.0
$ pip install pyshp==1.2.10
$ pip install shapely==1.6.3
If you are using Windows, follow this post to properly install geopandas and dependencies:http://geoffboeing.com/2014/09/using-geopandas-windows/
If you are using Anaconda, do not use PIP to install the packages above. Instead use conda to install them:
$ conda install plotly
$ conda install geopandas
However, the following code does work (not using chart_studio here):
In Anaconda Prompt:
conda create -n choropleth-test-plotly2 python=3.7
conda install plotly
conda install geopandas
In Jupyter Notebook:
import plotly as py
import plotly.figure_factory as ff
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.layout.template = None
fig.show()