0
$\begingroup$

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

$\endgroup$
1
$\begingroup$

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()
$\endgroup$
  • $\begingroup$ I went through the documentation and didn't find any solution that works.Can you give a specific example? Thanks. $\endgroup$ – Almog Dec 1 '20 at 11:45
  • $\begingroup$ I just extended my answer with a proper running example above. $\endgroup$ – squeezer44 Dec 2 '20 at 16:34
  • $\begingroup$ 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? $\endgroup$ – Almog Dec 3 '20 at 20:33
  • $\begingroup$ 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. $\endgroup$ – squeezer44 Dec 8 '20 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.