I’m trying to understand how to situate a data layer within a stack of vector layers using Plotly’s Mapbox functionality. I think this is possible with the following approach. Using Mapbox Studio, I’ve created two map styles: one which represents the base map that all data layers should be placed on top of and another which represents the remaining map layers that should be layered on above the data layers.
This example from the Plotly documentation seems to point to the viability of this approach.
Here’s demo code that I put together to try and realize the result I’m after. The last update_layout statement is not adding the Mapbox layer. Not sure what I’m missing here. Any suggestions? Maybe the Mapbox style spec can’t be passed for additional layers?
import plotly.graph_objects as go
import pandas as pd
us_cities = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")
fig = go.Figure(go.Scattermapbox(lat=us_cities["lat"], lon=us_cities["lon"]))
fig.update_layout(mapbox_style="mapbox://styles/diehl/cl9gh775w000014n2jwfncok7", mapbox_accesstoken=MAPBOX_ACCESS_TOKEN)
fig.update_layout(mapbox_center_lat=38, mapbox_center_lon=-97, mapbox_zoom=3.25)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.update_layout(
mapbox_layers=[
{
"sourcetype": "vector",
"source": ["mapbox://styles/diehl/cl9gha8ta000914qm137qf52q"]
}
])
fig.show()