我试图用彩色比例尺在choropleth地图上编码百分比。如何格式化刻度以显示百分比值(例如10%)而不是分数值(例如0.1)?我知道对于一个普通的X或Y轴你可以做
axis=alt.Axis(format='.0%')
,但我看不出如何使用此色阶的格式。
import altair as alt
import pandas as pd
from vega_datasets import data
alt.renderers.enable('notebook')
airports = pd.read_csv(data.airports.url)
airports = airports.groupby('state').agg({'iata': 'count'})
airports['id'] = range(1, len(airports) + 1)
airports['pct'] = airports['iata'] / airports['iata'].sum()
states = alt.topo_feature(data.us_10m.url, feature='states')
alt.Chart(states).mark_geoshape().encode(
color='pct:Q'
).transform_lookup(
lookup='id',
from_=alt.LookupData(airports, 'id', ['pct'])
).project('albersUsa')