Repository navigation
ScatterMapbox subplots not working #1728
Description
Hi,
First of all thank you for making plotly. It's amazing.
I've been trying to make a subplot of ScatterMapbox (e.g.: Two maps, one below the other) without success. I'm trying this in a jupyter notebook:
- linux debian buster
- Firefox 68.0.1
- python 3.6.9
- jupyter 1.0.0
- plotly 4.1.0
The code I use is:
fig = make_subplots(
rows=2, cols=1,
specs=[[{'type': 'mapbox'}],[{'type': 'mapbox'}]],
subplot_titles=('Montreal 1','Montreal 2'),
)
fig.add_trace(go.Scattermapbox(
lat=['45.5017'],
lon=['-73.5673'],
mode='markers',
marker=go.scattermapbox.Marker(
size=14
),
text=['Montreal'],
), row=1, col=1
)
fig.add_trace(go.Scattermapbox(
lat=['45.6017'],
lon=['-73.7673'],
mode='markers',
marker=go.scattermapbox.Marker(
size=14
),
text=['Montreal 2'],
), row=2, col=1
)
fig.update_layout(
hovermode='closest',
mapbox=go.layout.Mapbox(
accesstoken=mapbox_access_token,
bearing=0,
center=go.layout.mapbox.Center(
lat=45,
lon=-73
),
pitch=0,
zoom=5
)
)
fig.show()This results in an empty map:

In my browser console I have:
Error: No valid mapbox style found, please set `mapbox.style` to one of:
open-street-map, white-bg, carto-positron, carto-darkmatter, stamen-terrain, stamen-toner, stamen-watercolor
or register a Mapbox access token to use a Mapbox-served style.
Passing a mapbox_style to the layout does not seem to solve the issue.
Note that running the simple montreal example from the doc works properly, even adding a single map to the subplot works too:
fig = make_subplots(
rows=2, cols=1,
specs=[[{"type": "mapbox"}],[{"type": "mapbox"}]],
subplot_titles=("Montreal 1","Montreal 2"),
)
fig.add_trace(go.Scattermapbox(
lat=['45.5017'],
lon=['-73.5673'],
mode='markers',
marker=go.scattermapbox.Marker(
size=14
),
text=['Montreal'],
), row=1, col=1
)
fig.update_layout(
hovermode='closest',
mapbox=go.layout.Mapbox(
accesstoken=mapbox_access_token,
bearing=0,
center=go.layout.mapbox.Center(
lat=45,
lon=-73
),
pitch=0,
zoom=5
)
)
fig.show()I've tried passing multiple Scattermapbox to a figure's data but this results in two mapbox layers in the same map. At this point I'm starting to think that subplots are not supported with scattermapbox but as could not find anything regarding this in the docs, I'm probably missing something.
Activity
gmleon commentedon Mar 10, 2020
Hi, I have the same issue using the Mapbox choropleth.
Any updates?
Timost commentedon Mar 10, 2020
Personally I gave up trying to do that.
emmanuelle commentedon Mar 10, 2020
It seems indeed that mapbox traces don't interact well with subplots. You can still define more manually the domain of subplots as explained in https://community.plot.ly/t/subloting-mapbox-in-jupyter-notebook/16126. Below is an example with a more recent syntax
gmleon commentedon Mar 10, 2020
Thank you for your quick replies!
It just worked for me using the
update_layoutmethod like this:fig.update_layout(mapbox_style="carto-positron", mapbox2_style="carto-positron" )While printing out my figure's layout
print(fig.layout), I noticed that the problem is that only the first subplot keeps its original mapbox_style.But for using more than 1 subplot, you need to set
mapbox2_style,mapbox3_style, and so on.empet commentedon Mar 10, 2020
What Plotly version are you running? With 4.5.2 the usual code for defining mapbox-type subplots, and updating layout works as expected:
bandersen23 commentedon Nov 24, 2020
@Timost If you want the styles to be the same across all of your subplots you can also run:
This will mean you won't need to call add
mapbox{n}_stylen times.Timost commentedon Nov 24, 2020
@bandersen23 Wow thank you for the answer ! Good to know ! I'll keep that I mind for next time.
mmonto95 commentedon Apr 29, 2022
@bandersen23 Life saver!
gvwilson commentedon Aug 12, 2024
@archmoj is this addressed by your recent work?
archmoj commentedon Aug 12, 2024
@gvwilson
I think we may close this considering some fixes to mapbox since 2020.
If there the users encounter it again in latest versions please feel free to reopen it.
Thank you!
archmoj commentedon Aug 12, 2024
Possibly related to plotly/plotly.js#7068.
Let's see if these options would be available via
maplibre? cc: @birkskyumbirkskyum commentedon Aug 12, 2024
@archmoj , is there a python playground / REPL / kitchensink, similar to the
npm run startjavascript one?What is the best way to try out this in a python environment using the my local fork?
archmoj commentedon Aug 12, 2024
@birkskyum There is a way using this script and a successful run CircleCI run of
plotly.js/publish-distjob.But it's not very straightforward.
Here I suggest we wait for a plotly.js RC first (i.e. possibly today) and then when we merge plotly.py doc examples to master including maplibre, then it should be easier to test out these details.
Thank you!