【问题标题】:How to zoom mark_geoshape to a specific region in Altair?如何将 mark_geoshape 缩放到 Altair 中的特定区域?
【发布时间】:2021-02-04 15:00:01
【问题描述】:

我目前正在使用纽约市的地理数据框。但是,我希望我的图表只显示城市的特定部分。有没有办法在 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

谢谢!

【问题讨论】:

标签: python altair vega-lite


【解决方案1】:

是的,您可以使用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])

【讨论】:

    猜你喜欢
    • 2020-10-30
    • 1970-01-01
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 2022-09-24
    相关资源
    最近更新 更多