Skip to content

Add more projection options to Mapbox map layers in Python #4189

Closed as not planned
@wybert

Description

@wybert

Hi, I would like to see projection support in Mapbox map layers like, px.scatter_mapbox, such as 'globe' projection (which will make a tile-based 3d globe map). I noticed that Plotly is integrated with Mapbox-gl, and the Mapbox-GL support different projections, so it should be easy to have this option in Plotly. It looks like it's already supported in scatter_geo (see the doc)but not Mapbox layers.

See projections support in Mapbox-GL here. See what's looks like with projection here,
image
image

The code by the support the function should look like,

import pandas as pd
us_cities = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")

import plotly.express as px

fig = px.scatter_mapbox(us_cities, lat="lat", lon="lon", hover_name="City", hover_data=["State", "Population"],
                        color_discrete_sequence=["fuchsia"], zoom=3, height=300)
fig.update_layout(
    mapbox_style="white-bg",
    mapbox_layers=[
        {
            "below": 'traces',
            "sourcetype": "raster",
            "sourceattribution": "United States Geological Survey",
            "source": [
                "https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}"
            ]
        }
      ])
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}, projection= 'globe')
fig.show()

the projection option can be configured to support more projections

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions