【问题标题】:Altair: Globe map centeringAltair:全球地图居中
【发布时间】:2020-04-04 07:41:22
【问题描述】:

我正在通过 Altair 学习地图,这里的示例如下Example Gallery - World Projections

如何在我想要的 latlong 点设置 Globe 地图的中心?

下面是我尝试将地图居中在纬度 = 40 和经度 = 140 左右的失败代码:

import altair as alt
from vega_datasets import data

countries = alt.topo_feature(data.world_110m.url, 'countries')

alt.Chart(countries).mark_geoshape(
    fill='#666666',
    stroke='white'
).project(
    type= 'orthographic'
).properties(
    title='Orthographic'
).configure_projection(
    center= [140,40]
)

如您所见,地图仍以大西洋为中心,可能位于 [Long, Lat] = [0, 0]。

【问题讨论】:

    标签: python altair


    【解决方案1】:

    对于正交投影,是rotate 属性而不是center 属性决定了投影如何居中。 rotate 属性由围绕三个主轴的旋转度数组成。例如,要构建围绕 long=140, lat=40 的投影,您可以这样做:

    import altair as alt
    from vega_datasets import data
    
    countries = alt.topo_feature(data.world_110m.url, 'countries')
    
    alt.Chart(countries).mark_geoshape(
        fill='#666666',
        stroke='white'
    ).project(
        type= 'orthographic',
        rotate=[-140, -40 ,0]
    ).properties(
        title='Orthographic'
    )
    

    您可以在此站点上动态探索一些可用的投影及其配置:https://vega.github.io/vega/docs/projections/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-27
      相关资源
      最近更新 更多