python plotly express mapbox:在地图上配置自定义45度角
python plotly express mapbox: configure custom 45 degree angle on map
我使用 Plotly.express
choropleth_mapbox
来可视化给定城镇的郊区。我同时设置 center
和 zoom
来指定地图的经度和纬度中心+边界。我喜欢这样一个事实,即我还可以在渲染的可视化中更改地图的“角度”(俯仰角),例如 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()
我当前的视图如下所示:
我想用自定义“角度”渲染地图,如下所示:
可以使用以下信息设置地图的显示角度。
可能是 geojson 文件设置不正确,但是区域没有颜色。
fig.update_mapboxes(pitch=45)
我使用 Plotly.express
choropleth_mapbox
来可视化给定城镇的郊区。我同时设置 center
和 zoom
来指定地图的经度和纬度中心+边界。我喜欢这样一个事实,即我还可以在渲染的可视化中更改地图的“角度”(俯仰角),例如 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()
我当前的视图如下所示:
我想用自定义“角度”渲染地图,如下所示:
可以使用以下信息设置地图的显示角度。 可能是 geojson 文件设置不正确,但是区域没有颜色。
fig.update_mapboxes(pitch=45)