我试图在一个choropleth上设置自定义的颜色断点,但是刻度似乎不符合我的倾斜颜色放置。例如:
counties = alt.topo_feature(vega_data.us_10m.url, 'counties')
states = alt.topo_feature(vega_data.us_10m.url, 'states')
outlines = alt.Chart(states).mark_geoshape(
stroke='black'
).project('albersUsa')
domain = [df.min()['rep_vote_change'], 0, df.max()['rep_vote_change']]
range_ = ['darkred', 'orange', 'green']
colors = alt.Chart(counties).mark_geoshape().encode(
color=alt.Color('rep_vote_change:Q', scale=alt.Scale(domain=domain, range=range_))
).transform_lookup(
lookup='id',
from_=alt.LookupData(df, 'id', ['rep_vote_change'])
).project(
type='albersUsa'
).properties(
width=500,
height=300
)
colors + outlines
产生:
注意橙色的中心不是0。如何强制缩放颜色与域断点匹配?在
您需要将scale类型设置为
"linear"
,以使其按预期的方式工作。例如(使用更简单的图表,因为您没有提供数据):在将来的版本中,线性比例类型将是分段色阶的默认值;有关详细信息,请访问https://github.com/vega/vega-lite/issues/3980
相关问题 更多 >
编程相关推荐