plotly网站Map Configuration and Styling in Python介绍了如何自动缩放“地理地图”:
import plotly.express as px
fig = px.line_geo(lat=[0,15,20,35], lon=[5,10,25,30]) # Creates a "Geo map" figure
fig.update_geos(fitbounds="locations") # Automatic Zooming !!!!
fig.show()
这是可行的,而且,如果我尝试在“地图盒地图”上使用相同的方法,它不会应用自动缩放:
fig = px.scatter_mapbox(filtered_df, lat="latitude", lon="longitude", color="ID") # Creates a "Mapbox map" figure
fig.update_layout(mapbox_style="open-street-map")
fig.update_geos(fitbounds="locations") # Automatic Zooming not working!!!
在Mapbox Map Layers in Python中没有关于如何执行此操作的信息
基于这个question on plotly.com和first version of the function below我提出了以下最终解决方案:
Mapbox API documentation显示缩放基本上是对数缩放。因此,经过反复试验,以下功能对我有效:
注:
我在rv_geojson.py中编写了自己的函数以及其他
geojson
兼容函数它获取位置列表并查找矩形装订盒的几何高度和宽度,适合与墨卡托投影一起使用。它返回缩放和居中
把它当作
相关问题 更多 >
编程相关推荐