0

I copied the "Indexing by GeoJSON Properties" example as seen on the Choropleth Maps in Python page. The code was executed with no error but there was no map showing, only the legend. In addition, the 'box', 'pan', 'zoom' options show but don't work. I have the latest plotly version, installed via pip. any ideas? Thanks.

enter image description here

Almog
  • 125
  • 1
  • 6

1 Answers1

2

You executed the code either inside a cell of a jupyter notebook or in jupyter lab. That explains why no graph was shown. If you would ran the same code as a pure python script it shows the graph properly.

Plotly provides two different solutions for getting it running inside jupyter:
Plotting Inline
Please search for Plotting Inline on that page to find the paragraph that explains the solution en detail.

Proper running example purePython and Jupyter Notebook

I just let it ran as it is also as purePython and as Jupyter Notebook cell:

import plotly.express as px

df = px.data.election()
geojson = px.data.election_geojson()

fig = px.choropleth(df, geojson=geojson, color="Bergeron",
                    locations="district", featureidkey="properties.district",
                    projection="mercator"
                   )
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
squeezer44
  • 161
  • 3
  • I went through the documentation and didn't find any solution that works.Can you give a specific example? Thanks. – Almog Dec 01 '20 at 11:45
  • I just extended my answer with a proper running example above. – squeezer44 Dec 02 '20 at 16:34
  • Thanks a lot! I tried it on my personal laptop and it works just fine. The problem is my office PC. Do you have any idea what can cause it? – Almog Dec 03 '20 at 20:33
  • It sounds like it would be an IT security issue related to your office PC. js seems to be prohibited. If you accept my answer to solve your question please mark it above. That shows visually to the community in case someone else would have a similar problem. Thx. – squeezer44 Dec 08 '20 at 17:43