簡體   English   中英

在 Altair 分層圖表中設置顏色

[英]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()

這里來自數組的顏色:

#170c3b #fa8d0b
在此處輸入圖像描述 在此處輸入圖像描述

這里的情節改變了顏色: 在此處輸入圖像描述

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.

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