如何缩放 mark_geoshape 到 Altair 中的特定区域?

How to zoom mark_geoshape to a specific region in Altair?

我目前正在处理纽约市的地理数据框。但是,我希望我的图表只显示城市的特定部分。有没有办法在 mark_geoshape?

中设置纬度和经度的最大值和最小值

我希望我的图表仅显示从纬度 40.64 到 40.84 和经度 -74.01 到 -73.9。

这是我当前的代码:

ntaMap = alt.Chart(ntaData).mark_geoshape(
    fill='whitesmoke',
    stroke='gray',
    strokeWidth=0.5
).encode(
    tooltip=['NTAName','BoroName']
).properties(
    width=500,
    height=500,
    title='Neighborhood Tabulation Areas'
).configure_view(
    strokeWidth=0
)

ntaMap

谢谢!

是的,您可以使用 scale 缩放和 translate 平移 (Example notebook)

import altair as alt
from vega_datasets import data


world = data.world_110m.url

alt.Chart(alt.topo_feature(world, 'countries')).mark_geoshape(
    fill='#2a1d0c', stroke='#706545', strokeWidth=0.5
).project(
    type='mercator', scale=400, translate=[100, 550])