【发布时间】:2019-08-21 22:23:01
【问题描述】:
我很喜欢 Altair 创建 choropleth 地图!然而,我最大的问题是我无法弄清楚如何更改图例的大小。我已经阅读了文档并尝试了几件事无济于事。
这是一个使用 Altair 文档中的 unemployment map by county 的示例。我添加了一个“配置”层来更改地图和图例上标题的字体大小。请注意“config”中代码的 .configure_legend() 部分。
counties = alt.topo_feature(data.us_10m.url, 'counties')
source = data.unemployment.url
foreground = alt.Chart(counties).mark_geoshape(
).encode(
color=alt.Color('rate:Q', sort="descending", scale=alt.Scale(scheme='plasma'), legend=alt.Legend(title="Unemp Rate", tickCount=6))
).transform_lookup(
lookup='id',
from_=alt.LookupData(source, 'id', ['rate'])
).project(
type='albersUsa'
).properties(
title="Unemployment Rate by County",
width=500,
height=300
)
config = alt.layer(foreground).configure_title(fontSize=20, anchor="middle").configure_legend(titleColor='black', titleFontSize=14)
config
图像应该是这样的:
如果我像这样更改地图的大小:
counties = alt.topo_feature(data.us_10m.url, 'counties')
source = data.unemployment.url
foreground = alt.Chart(counties).mark_geoshape(
).encode(
color=alt.Color('rate:Q', sort="descending", scale=alt.Scale(scheme='plasma'), legend=alt.Legend(title="Unemp Rate", tickCount=6))
).transform_lookup(
lookup='id',
from_=alt.LookupData(source, 'id', ['rate'])
).project(
type='albersUsa'
).properties(
title="Unemployment Rate by County",
width=900,
height=540
)
config = alt.layer(foreground).configure_title(fontSize=20, anchor="middle").configure_legend(titleColor='black', titleFontSize=14)
config
图例的大小保持不变,因此与地图相比,它现在看起来很小:
或者,如果我将地图尺寸缩小,则图例会很大!
我尝试了大约十几种不同的方法,但均无济于事。
有人有解决办法吗?
【问题讨论】:
标签: python gis data-science vega-lite altair