[英]Setting Colors in Altair Layered Chart
與在 Altair 圖表中設置顏色類似,我正在使用分層圖表,並且我喜歡設置顯式顏色。 不知何故,當我使用答案中的解決方案時,我的顏色總是會變成一些任意顏色。 我想知道,如果有人知道,為什么會發生這種情況以及如何強制 altair 使用顏色數組中給出的顏色。
這是一個測試示例:
import altair as alt
from vega_datasets import data
source = data.movies()
colors = ['#170c3b', '#fa8d0b']
plot = alt.Chart(source).mark_line().encode(
x=alt.X("IMDB_Rating", bin=True),
y=alt.Y(
alt.repeat("layer"), aggregate="mean", title="Mean of US and Worldwide Gross"
),
color=alt.datum(alt.repeat("layer")),
).repeat(
layer=["US_Gross", "Worldwide_Gross"]
).configure_range(
category=alt.RangeScheme(scheme=colors)
)
plot.show()
這里來自數組的顏色:
category=alt.RangeScheme(scheme=colors)
應該改為category=alt.RangeScheme(colors)
。
import altair as alt
from vega_datasets import data
source = data.movies()
colors = ['#170c3b', '#fa8d0b']
plot = alt.Chart(source).mark_line().encode(
x=alt.X("IMDB_Rating", bin=True),
y=alt.Y(
alt.repeat("layer"), aggregate="mean", title="Mean of US and Worldwide Gross"
),
color=alt.datum(alt.repeat("layer")),
).repeat(
layer=["US_Gross", "Worldwide_Gross"]
).configure_range(
category=alt.RangeScheme(colors)
)
plot
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.