[英]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.