data-visualization - Vega-Lite/牵牛星 : How to Center or Crop a Map of Europe?

标签 data-visualization gis vega vega-lite altair

我有一些关于欧洲国家的数据。我正在尝试使用 world-110m 数据在 Altair/Vega-Lite 中创建可视化。技术上一切正常,除了国家的编码边界还包括遥远的领土,产生了一个看起来像这样的糟糕 map :

Bad Europe Map

这是我的代码:

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

map = alt.Chart(countries).mark_geoshape(
    stroke='black'
    ).encode(
    color=alt.Color('SomeStat:Q', sort="descending", scale=alt.Scale(
        scheme='inferno', domain=(min_value,max_value)), legend=alt.Legend(title="", tickCount=6))
).transform_lookup(
    lookup='id',
    from_=alt.LookupData(source, 'CountryId', ['SomeStat', 'CountryName'])
).project(
    type='mercator'
)

有没有办法裁剪这张 map 或将其居中,这样我就只能看到欧洲而不是世界各地的偏远地区?

或者,我应该使用仅包含欧洲的更好的公共(public)数据集吗?

最佳答案

我没有你的 df数据集,所以我发布了一个相当简单的例子。

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= 'mercator',
    scale= 350,                          # Magnify
    center= [20,50],                     # [lon, lat]
    clipExtent= [[0, 0], [400, 300]],    # [[left, top], [right, bottom]]
).properties(
    title='Europe (Mercator)',
    width=400, height=300
)

enter image description here

可以通过scale控制 map View 和 center , 以及它的实际地 block 大小( widthheight )。

  • scale : 放大参数
  • center : View 的中心点

如果您需要进一步裁剪 map 的任何部分,clipExtent可能有用。请注意 - 此数组代表像素大小,而不是地理坐标。 (在上面的示例中,我将其设置为 [[0, 0], [400, 300]],因此它保留了整个 400x300 px View 。

关于data-visualization - Vega-Lite/牵牛星 : How to Center or Crop a Map of Europe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61135952/

相关文章:

math - GIS 开发的核​​心数学

Delphi计算WGS84 2点的交集

google-colaboratory - 如何在 Google Colab 中显示 Vega 可视化

python - 获取groupby后每列的百分比

javascript - d3.缺失数据。仅绘制每组中的初始值

python - 像plotly.express 中一样使用plotly.graph_objs 创建直方图

sql - 计算有序数组中节点之间的总距离

转换中的 Vega-lite 多重聚合

javascript - 如何在 vega 中使用 `rule` 标记

r - 消除对基础 R 中包的需求?