Search code examples
plotlyplotly-python

cannot cancel country boundary in plotly scatter_mapbox


New to plotly, I'm trying drawing a scatter_map. For some reason, I want to cancel the country border by the code as follows:

fig = px.scatter_mapbox(
        df, lat="lat", lon="lon", color="var_c", size='var_s',
        custom_data=['city', 'var_c', 'var_s'],
        mapbox_style="open-street-map",
        center=dict(lat=34.3227, lon=108.5525), 
        zoom=3
    )
fig.update_geos(
        showcountries=False
    )

But only the px.scatter_mapbox works and coutry boundaries have not be deleted. While I use go.Scattergeo(), It works:

fig = go.Figure(go.Scattergeo())
fig.update_geos(
        showcountries=False
    )

I want to know whether update_geos conflict with px.scatter_mapbox(according to offical tutorial, they don't conflict), and how can I fix it? Thanks in advance.


Solution

  • update:

    I solved this question, actually px.scatter_mapbox can't be changed by update_geos. And if anyone else want to change the style of scatter_mapbox, there is my solution:

    fig.update_layout(
            mapbox=dict(
                accesstoken=mapbox_access_token,
                style='mapbox://styles/your_customed_style'
            )
        )
    

    mapbox_access_token is a string defined before. It's your own mapbox token, you can get it through https://docs.mapbox.com/ .

    And you can create a new style of mapbox (https://docs.mapbox.com/help/tutorials/create-a-custom-style/ may helps), to delete country boundary, to change themes of map, or do anything you want to do.