question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ScatterMapbox subplots not working

See original GitHub issue

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: Screenshot from 2019-08-19 20-04-14 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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
bandersen23commented, Nov 24, 2020

@Timost If you want the styles to be the same across all of your subplots you can also run:

fig.update_mapboxes(style='open-street-map)

This will mean you won’t need to call add mapbox{n}_style n times.

1reaction
mmonto95commented, Apr 29, 2022

@bandersen23 Life saver!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subloting mapbox in jupyter notebook - Plotly Community Forum
Hey everyone, I'm trying to sublots 4 mapbox images. The goal would be to display 4 maps side-by-side, but I can't find how...
Read more >
Include legend for go.scattermapbox subplot figure - Plotly
1 Answer 1 · Brilliant, thank you. The legend is function is working but the color mapping appears off. · I found out...
Read more >
plotly.subplots: helper function for laying out multi-plot figures
Figure with predefined subplots configured in 'layout'. Parameters. rows (int (default 1)) – Number of rows in the subplot grid. Must be greater...
Read more >
Subplots in Plotly — Scientific Visualization Using Python
Creating subplots in plotly is not supported using plotly-express . Instead, we have to manually build our figures using plotly graph objects Plotly...
Read more >
Chart::Plotly::Trace::Scattermapbox - MetaCPAN
Determines whether or not an item corresponding to this trace is shown in the legend. stream. subplot. Sets a reference between this trace's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found