I’m trying to plot points from a CSV file with scatter_mapbox, and would like to add layers representing the map of the island the points are on stored in a Geojson file. But, when I try to add a Geojson layer to my plot it doesn’t seem to render, though the foreground points render just fine.
Here is the code I’m using:
import pandas as pd
import plotly.express as px
df = pd.read_csv("exampleDPs.csv")
import geojson
with open('island.geojson') as f:
gj = geojson.load(f)
fig = px.scatter_mapbox(df, lat="lat", lon="long", hover_name="id", hover_data=["Timestamp"],
color_discrete_sequence=["fuchsia"], zoom=15, height=400)
fig.update_layout(mapbox_style="white-bg")
fig.update_layout(mapbox_layers=[{
"name": "Island",
"below": 'traces',
"sourcetype": "geojson",
"type": "fill",
"color": "green",
"source": [gj]
}])
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
That results in points on a blank white field. Can anyone help me get the map data to show up? I’ve tried modifying all the relevant parameters listed here but made no headway. Assistance would be much appreciated.
(To give a bit more detail, this is data from the 2021 Vast Challenge representing a fictional Greek island. The maps came as shape files, but I put them in geojson format using qGIS. I’m working in Jupyter Notebook on Windows, in Python 3.8.8 with Plotly 5.1.0, and Geojson 3.0.1.)