You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now with scattermapbox we have to manually set center and zoom but it would be great to have a flag that uses the built-in Mapbox machine to fit bounds. Something like layout.mapbox.fitbounds: true | false
This is equivalent to autorange for cartesian axes, so has all the same issues with figure mutation and impliedEdits. Seems to me the ideal - though this may need to happen in a major bump - would be no new attribute at all, just better defaults. So if you omit both center and zoom we automatically invoke fitbounds. Likewise if you only provide center we tell mapbox to pick a zoom that still shows all the data (but if you just changed center by panning in the GUI, zoom should not change!), and if you only provide zoom we use the same center as fitbounds would use.
Of course - we can avoid pushing center and zoom back into the figure, at least with an appropriate stash of the auto results. But the impliedEdits complications will still be there... say the user zooms (either via GUI or some other interface like RCE): we'll need to explicitly clear fitbounds, then center is no longer set automatically so we'll need to explicitly pull into the figure whatever the auto center value was. All of this is much simpler if auto, rather than being an attribute in its own right, is just the absence of an explicit value, like in the histogram autobin revamp #3044.
Is there any update on this for mapbox subplots? I'm moving from geo to mapbox subplots and would have to manually find the zoom levels for each (over 5000) region (can get the center from d3.geoCentroid).
Is there any way to access the calculated or inferred zoom and center when fitbounds is set to locations for geo subplots?
A community PR for this feature would certainly be welcome, but our experience is deeper features like this are difficult to complete without the Plotly maintainers leading the effort.
Sponsorship range: $10k-$15k
What Sponsorship includes:
Completion of this feature to the Sponsor's satisfaction, in a manner coherent with the rest of the Plotly.js library and API
Tests for this feature
Long-term support (continued support of this feature in the latest version of Plotly.js)
Plotly Express does not automatically fix the zoomlevel, and the center is just done with the centroid of the scatter points.
Note that the problem in Plotly.js is a bit more complex as a mapbox subplot can have multiple traces on it, including choropleths etc. Plotly Express has access to the entire dataset up front, and px.scatter_mapbox only makes scatter traces, so computing the centroid is much easier.
Activity
alexcjohnson commentedon Jan 14, 2019
This is equivalent to
autorangefor cartesian axes, so has all the same issues with figure mutation andimpliedEdits. Seems to me the ideal - though this may need to happen in a major bump - would be no new attribute at all, just better defaults. So if you omit bothcenterandzoomwe automatically invokefitbounds. Likewise if you only providecenterwe tell mapbox to pick azoomthat still shows all the data (but if you just changedcenterby panning in the GUI,zoomshould not change!), and if you only providezoomwe use the samecenterasfitboundswould use.nicolaskruchten commentedon Jan 14, 2019
Oh to be clear, I thought this would just call the native MapBox fitBounds after rendering, and not actually write the data back to the figure :)
alexcjohnson commentedon Jan 14, 2019
Of course - we can avoid pushing
centerandzoomback into the figure, at least with an appropriate stash of the auto results. But theimpliedEditscomplications will still be there... say the user zooms (either via GUI or some other interface like RCE): we'll need to explicitly clearfitbounds, thencenteris no longer set automatically so we'll need to explicitly pull into the figure whatever the autocentervalue was. All of this is much simpler if auto, rather than being an attribute in its own right, is just the absence of an explicit value, like in the histogram autobin revamp #3044.etpinard commentedon Dec 11, 2019
#4419 implements (or attempts to)
fitboundson geo subplot.Mapbox subplots should be able to reuse much of the logic there.
nicolaskruchten commentedon Dec 12, 2019
Awesome! Sorely needed in Mapbox-land :)
Krichardson846 commentedon Apr 29, 2020
Hello! Are there any updates on this feature? This is one feature that would really save my dash app a lot of troubles!
greenafrican commentedon May 18, 2020
Is there any update on this for mapbox subplots? I'm moving from geo to mapbox subplots and would have to manually find the zoom levels for each (over 5000) region (can get the center from d3.geoCentroid).
Is there any way to access the calculated or inferred
zoomandcenterwhenfitboundsis set tolocationsfor geo subplots?nicolaskruchten commentedon May 18, 2020
We’ll definitely post an update once we have one :)
I don’t have a good workaround for you at the moment either unfortunately.
jackparmer commentedon Sep 10, 2020
This issue has been tagged with
NEEDS SPON$ORA community PR for this feature would certainly be welcome, but our experience is deeper features like this are difficult to complete without the Plotly maintainers leading the effort.
Sponsorship range: $10k-$15k
What Sponsorship includes:
Please include the link to this issue when contacting us to discuss.
ainar commentedon Jun 9, 2021
It seems that Plotly Express already find the right level of zoom and center... How is it done?
nicolaskruchten commentedon Jun 14, 2021
Plotly Express does not automatically fix the zoomlevel, and the center is just done with the centroid of the scatter points.
Note that the problem in Plotly.js is a bit more complex as a mapbox subplot can have multiple traces on it, including choropleths etc. Plotly Express has access to the entire dataset up front, and
px.scatter_mapboxonly makes scatter traces, so computing the centroid is much easier.pencilcheck commentedon Dec 4, 2022
Right now it seems like the best workaround is to add layout
To center and zoom in manually