plotly express choropleth map not rendering in jupyter notebook
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2023 12:07 AM
I have the following code which should render a choropleth map.
import plotly.express as px
import geopandas as gpd
# Example GeoJSON file with polygon geometries
geojson_file = 'example.geojson'
# Read GeoJSON file into GeoDataFrame
*** = gpd.read_file(geojson_file)
# Create Mapbox GL plot
fig = px.choropleth_mapbox(
***,
geojson=***.geometry,
locations=***.index,
color='property',
center=dict(lat=0, lon=0),
zoom=1,
mapbox_style="carto-positron"
)
fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
fig.show()
however, when I run the code in jupyter notebook, I get a blank output. Map doesn't render.
Labels:
- Labels:
-
Jupyternotebook
1 REPLY 1
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2023 09:00 AM
@Keval Shah :
There could be several reasons why the choropleth map is not rendering in your Jupyter notebook. Here are a few things you could try:
- Check that the GeoJSON file is loaded correctly: Make sure that the GeoDataFrame has been loaded correctly by checking the output of gpd.read_file(geojson_file)
- Check the GeoDataFrame index: The locations argument in px.choropleth_mapbox expects a list of strings or numbers representing the index of the GeoDataFrame. Make sure that the index is set and that it is of the correct type.
- Check that the color column exists: Make sure that the column specified in the color argument exists in the GeoDataFrame.
- Check that Mapbox API token is set: In order to display the map, you need to have a valid Mapbox API token. Make sure that you have set this token using mapbox_token environment variable, or by passing it directly to px.choropleth_mapbox
- Check that your internet connection is working: If you are using Mapbox as a basemap, you need an internet connection to load the map tiles. Make sure that you have a stable internet connection and that there are no issues with your firewall or network settings.
- You can also try adding fig.show() at the end of the code to display the map in a separate window, rather than inline in the Jupyter notebook.
If none of these solutions work, you could try using a different library to render the choropleth map, such as Folium or Bokeh.

