【问题标题】:Problem while displaying Choropleth map for UK using Altair使用 Altair 显示英国的 Choropleth 地图时出现问题
【发布时间】:2022-01-12 14:52:29
【问题描述】:
我正在从英国地区的两个不同来源下载数据集。我正在使用 Altair 代码来显示 Choropleth Map。但这是我使用以下代码为两个数据集得到的结果:
_map = alt.Chart(geo_uk, title='UK Map').mark_geoshape().encode().properties(width=500,height=300);
Link to used data source (GeoJson file)
【问题讨论】:
标签:
python
jupyter-notebook
altair
choropleth
【解决方案1】:
我不是一直用altair,所以不知道我的回答是否让你满意。我使用给定 geojson 文件中的可用信息创建了一张地图。我的回答基于this answer。如果地图不是您想要的,您可能需要在世界大地测量系统中对其进行转换。
import altair as alt
import json
file = './data/Local_Authority_Districts__April_2019__UK_BGC_v2.geojson'
with open(file) as f:
data_json = json.load(f)
geo_uk = alt.Data(values=data_json, format=alt.DataFormat(property='features',type='json'))
_map = alt.Chart(geo_uk, title='UK Map').mark_geoshape(
).encode(
color="properties.LAD19NM:N"
).project(
type='identity', reflectY=True
).properties(width=800,height=600)
_map