Plotly 的layout.geo.fitbounds 属性未按预期工作

发布于 2025-01-09 04:43:15 字数 717 浏览 2 评论 0原文

我正在使用 Plotly Express/Dash 解码折线以映射路线。我能够成功绘制路线并在 Dash 中显示地图,但无法让 layout.geo.fitbounds 属性按照文档中所述工作:

可以将 layout.geo.fitbounds 属性设置为 locations 自动设置中心和经纬度范围 根据绘制的数据。

示例代码:

import plotly.express as px
import dash_core_components as dcc

fig = px.line_geo(lat=[0,15,20,35], lon=[5,10,25,30])
fig.update_geos(fitbounds="locations")

dcc.Graph(figure=fig)
app = dash.Dash()
app.layout = html.Div([
    dcc.Graph(figure=fig)
])
app.run_server()

这会产生与我不向其传递 fitbounds 参数时相同的缩放级别: 映射的示例数据

我是否需要在 Dash 端进行一些格式化才能使自动缩放工作?

任何建议都非常感激。谢谢。

I'm decoding polylines to map routes using Plotly Express/Dash. I'm able to successfully plot routes and display the maps in Dash, but I'm unable to get the layout.geo.fitbounds attribute to work as described in the documentation:

The layout.geo.fitbounds attribute can be set to locations to
automatically set the center and latitude and longitude range
according to the data being plotted.

Example code:

import plotly.express as px
import dash_core_components as dcc

fig = px.line_geo(lat=[0,15,20,35], lon=[5,10,25,30])
fig.update_geos(fitbounds="locations")

dcc.Graph(figure=fig)
app = dash.Dash()
app.layout = html.Div([
    dcc.Graph(figure=fig)
])
app.run_server()

This results in the same zoom level as when I don't pass it a fitbounds parameter:
Sample data mapped

Do I need to be doing some formatting on the Dash end to make auto-zoom work?

Any advice greatly appreciated. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文