I have been unsuccessful in displaying a geojson with plotly express and Graph objects.
I first load the geojson into a geodataframe and then try to display it.
I receive the error
ValueError: The first argument to the plotly.graph_objs.Choroplethmapbox
constructor must be a dict or
an instance of :class:plotly.graph_objs.Choroplethmapbox
Which I have seen popping up in different threads and I cannot find what to do. I link the file and here is the simple code I use.
import geopandas as gpd
import json
import plotly.graph_objects as go
with open('Protection_zones.geojson') as f:
geojson=json.load(f)
gdf = gpd.GeoDataFrame.from_features(geojson,crs=27700)
gdf_p=gdf.to_crs(epsg=4326)
fig = go.Figure(
go.Choroplethmapbox(gdf_p,
geojson=gdf_p.geometry,
locations=gdf_p.index,
z=gdf_p["SwimTime"],
colorscale="Viridis"
)
)
Supposedly it could be an indexing issue but I donβt see any of it.
Thanks in advance
PS: plotting in QGIS and Geopandas works fine