简体   繁体   中英

Setting Colors in Altair Layered Chart

Similar to Setting colors in Altair charts I am using a layered chart and I like to set excplicit colors. Somehow, when I use the solution from the answer, my colors are always changing to some arbitrary colors. I wonder, if anyone knows, why this happens and how to force altair to use the colors given in the colors array.

Here a test example:

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()

Here the colors from the array:

#170c3b #fa8d0b
在此处输入图像描述 在此处输入图像描述

Here the plot with changed colors: 在此处输入图像描述

The category=alt.RangeScheme(scheme=colors) should be category=alt.RangeScheme(colors) instead.

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

yields:
阴谋

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM