Question

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

Was it helpful?

Solution

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange
scroll top