plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.26k stars 2.55k forks source link

Mapbox stamen styles not working #4425

Closed shawnrosofsky closed 8 months ago

shawnrosofsky commented 12 months ago

It appears that the stamen styles (stamen-terrain, stamen-toner, stamen-watercolor) no longer work on mapbox maps. Using one of these styles, just gives a blank map under the data provided to the plotting function. I could provide an example of trying this myself, but it appears that the example pages using this style also have this problem such as https://plotly.com/python/mapbox-density-heatmaps/.

Is this a bug or is there some issue with mapbox no longer supporting stamen styles?

alexcjohnson commented 12 months ago

Stamen switched to a paid model under Stadia Maps. This is addressed in plotly.js v2.27.1 which we will incorporate in a new plotly.py release shortly.

LiamConnors commented 8 months ago

This was included in the latest Plotly.py release, 5.19. The docs show examples of using a token for the stamen styles https://plotly.com/python/mapbox-density-heatmaps/#stamen-terrain-base-map-stadia-maps-token-needed-density-mapbox-with-plotlyexpress

rmthomps commented 7 months ago

I made my token, cut-and-pasted the example from the link Liam provided above into a Jupyter notebook, and it still doesn't work. The data is plotting fine but the background is missing.

tuopouk commented 7 months ago

I made my token, cut-and-pasted the example from the link Liam provided above into a Jupyter notebook, and it still doesn't work. The data is plotting fine but the background is missing.

I'm experiencing the same issue. The data gets plotted but the map background is empty. I'm using Plotly 5.20.0

Coding-with-Adam commented 7 months ago

This actually works for me @tuopouk @rmthomps .

I used my own mapbox token in this code and I got the background to display fine. I'm using Plotly 5.20.0 and the Firefox browser.

import plotly.graph_objects as go
import pandas as pd

token = 'my-token'

quakes = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')

fig = go.Figure(go.Densitymapbox(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude,
                                 radius=10))
fig.update_layout(mapbox_style="stamen-terrain", mapbox_center_lon=180, mapbox_accesstoken=token)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
tuopouk commented 7 months ago

For me with that exact code this kind of map gets generated. The result is the same whether it's a mapbox token or a stadia token.

image

I also tried other stamen types (stamen-watercolor and stamen-toner) but with the same result as above. I tried the rendering in VS Code and exported it to html to open it with Firefox but the background seems to be lacking still. @Coding-with-Adam Did you get the map background rendered.

For instance the open-street-map renders correctly with both tokens image

Coding-with-Adam commented 7 months ago

hi @tuopouk I'm not sure what's the difference, why it's not rendering for you. Yes, I was able to get the map background rendered.

tuopouk commented 7 months ago

hi @tuopouk I'm not sure what's the difference, why it's not rendering for you. Yes, I was able to get the map background rendered.

@Coding-with-Adam Did you use the general default token or a custom token?

Coding-with-Adam commented 7 months ago

I used a custom token. You?

empet commented 7 months ago

@Coding-with-Adam I think that what you call a general token is a mapbox token, while a custom one is got from stadiamaps.com. Isn't it?

ossings commented 7 months ago

Hello, I'm also having this problem, using plotly version 5.20. When using the follow code I get a map with no background.

stadio_token = 'my_stadiamaps_token'
fig = px.scatter_mapbox(df, 
                        lat='lat', 
                        lon='long, 
                        color='categorical_chain_name',
                        center=dict(lat=51.44, lon=7.35), 
                        zoom=12,
                        hover_name='categorical_chain_name'
                        )

fig.update_layout(mapbox_style="stamen-terrain", mapbox_accesstoken=stadia_token)

fig.update_layout(legend = dict(bordercolor='rgb(100,100,100)',
                                borderwidth=2,
                                itemclick= 'toggleothers',
                                font = dict(family = "Courier", size = 20, color = "black"),

                                x=0.75,
                                y=0.75))

fig.show()

fig.write_html(out.html')

grafik

I have also tried using px.set_mapbox_access_token(stadia_token), with no change. I couldnt find the equivalent method for Stadiamaps. incidentally, there are also no credits being removed from my Stadiamaps quota.

etiennecelery commented 5 months ago

This isn't working for me as well. Tried several options without success. Stadia Maps don't appear to be working.