簡體   English   中英

有沒有辦法用合並數據反轉 altair choropleth map 的配色方案?

[英]Is there a way to reverse the color scheme of an altair choropleth map with binned data?

因此,我正在嘗試使用 Altair 中的分箱數據在縣級創建一個等值線 map。 我讓 bin function 開始工作,但我無法反轉配色方案的方向。 如果我使用以下參數,我可以使用非合並數據更改配色方案的方向:

sort="descending"

對於分箱數據,它不會出現錯誤,但排序參數不會執行任何操作,這是我使用 vega-lite 畫廊示例 map 搞砸的完整代碼:

import altair as alt
from vega_datasets import data

counties = alt.topo_feature(data.us_10m.url, 'counties')
source = data.unemployment.url

alt.Chart(counties).mark_geoshape().encode(
    color=alt.Color('rate:Q', bin=alt.Bin(maxbins=7), sort="descending", scale=alt.Scale(scheme='yelloworangered'))
).transform_lookup(
    lookup='id',
    from_=alt.LookupData(source, 'id', ['rate'])
).project(
    type='albersUsa'
).properties(
    width=500,
    height=300
)

有沒有辦法用分箱數據反轉配色方案? 在這個例子中,我想要的是將失業率較高的縣設為黃色,將失業率較低的縣設為紅色。

您可以通過設置reverse=True來反轉 Altair 中的任何比例(無需排序)。 在你的情況下:

scale=alt.Scale(scheme='yelloworangered', reverse=True)

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM