【问题标题】:python plotly express mapbox: configure custom 45 degree angle on mappython plotly express mapbox:在地图上配置自定义45度角
【发布时间】:2021-04-25 13:58:37
【问题描述】:

我使用Plotly.express choropleth_mapbox 来可视化给定城镇的郊区。我同时设置了centerzoom 来指定地图的经纬度中心+ 边界。我喜欢这样一个事实,即我还可以在渲染的可视化中更改地图的“角度”(俯仰角),例如从地图上的西南(方位角)看的 45 度角。有没有办法用预先指定的“角度”(方向、高度、角度)加载地图?请参阅下面的图片进行说明。

我的代码如下:

import plotly.express as px
import pandas as pd
import json

with open("geojson_suburbs.json") as response:
    suburbs = json.load(response)

""" geojson_suburbs.json:
{
    "type": "FeatureCollection", 
    "features": [
        {"type": "Feature", "properties": {"suburb": "a"}, "geometry": {"type": "Polygon", "coordinates": [[[4.7582, 52.2536], [4.7581, 52.2513], [4.7582, 52.2536]]]}, "id": "a"},
        {"type": "Feature", "properties": {"suburb": "b"}, "geometry": {"type": "Polygon", "coordinates": [[[4.7582, 52.2536], [4.7666, 52.2544], [4.7582, 52.2536]]]}, "id": "b"}
    ]
}
"""


df = pd.DataFrame(data={'suburb': ['a', 'b'], 'phase': ['d', 'e']})

mapbox_token='pk.eyJxxx'
px.set_mapbox_access_token(mapbox_token)

fig = px.choropleth_mapbox(
    df, 
    geojson=suburbs, 
    locations='suburb',
    color='phase',
    color_continuous_scale="Viridis",
    range_color=(0, 2),
    zoom=14, 
    center = {"lat": 52.2540, "lon": 4.7641},
    opacity=0.2)

fig.show()

我当前的视图如下所示:

我想用自定义的“角度”渲染地图,如下所示:

【问题讨论】:

    标签: python plotly mapbox plotly-dash


    【解决方案1】:

    可以使用以下信息设置地图的显示角度。 可能是 geojson 文件设置不正确,但区域没有着色。

    fig.update_mapboxes(pitch=45)
    

    【讨论】:

    • 官方reference可以在这里找到。也可以左右旋转。
    • 谢谢!正是我想要的!
    猜你喜欢
    • 2021-09-18
    • 2017-01-26
    • 2020-04-24
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多