【问题标题】:Setting a starting location to Plotly Choropleth without using locationmode在不使用 locationmode 的情况下将起始位置设置为 Plotly Choropleth
【发布时间】:2021-03-01 03:12:49
【问题描述】:

我目前正在尝试可视化汉堡市各区的地理数据。使用 plotly.graph_objects 和关联的 GeoJSON 文件创建 choropleth 工作正常。

但是,当我正在绘制汉堡市时,我无法使用指定的位置模式之一,我必须手动放大 - 对于每个单独的情节,对于每次执行,这非常麻烦。

我能否以某种方式使用经度/纬度坐标,例如类似于 Folium 的 zoom_start,或者我缺少的任何其他关键字来以编程方式限制选择?

为了完整起见,附上到目前为止的代码(创建了子图,而每个子图都是来自可视化为 graph_objects.Choropleth 实例的数据框的数据,并且可以单独触摸(缩放,...)。

import plotly
import plotly.graph_objects as go

choro_overview = plotly.subplots.make_subplots(
    rows=6, cols=2, specs=[[{'type': 'choropleth'}]*2]*6,
    subplot_titles = df_main.columns[5:],
    horizontal_spacing = 0.1,
)

cbar_locs_x = [0.45, 1]
cbar_locs_y = np.linspace(0.95, 0.05, 6)

for ii, column in enumerate(df_main.columns[5:]):
    placement = np.unravel_index(ii, (6, 2))
    choro_overview.add_trace(
        go.Choropleth(
            locations = df_main['District'],
            z = df_main[column],
            geojson=geojson_src,
            featureidkey='properties.name',
            colorbar=dict(len=np.round(1/9, 1), x=cbar_locs_x[placement[1]], y=cbar_locs_y[placement[0]]),
            name=column,
            colorscale='orrd',
        ), row=placement[0]+1, col=placement[1]+1

【问题讨论】:

    标签: python plotly


    【解决方案1】:

    后来我通过调用update_geos()发现关键字不在go.Choropleth中,而是在图中本身。 归功于plotly automatic zooming for "Mapbox maps"

    【讨论】:

    • 这可能有助于详细说明这个答案,我不得不四处寻找以查看所引用的内容。
    猜你喜欢
    • 2018-01-03
    • 1970-01-01
    • 2018-03-28
    • 2015-07-13
    • 2016-12-08
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多