我是 Altair 的新手,我正在尝试制作一个带有颜色对数比例的热图,并且还选择了一个非默认配色方案(默认方案使用的范围很小,而且我想要从浅到深的颜色)。我发现我可以很容易地得到一个对数刻度type=log
,但是一旦我这样做了,这个scheme=
参数就会被忽略。如果我改为手动设置高低颜色range=
,效果很好。
我进一步发现,如果我type=
以任何方式显式设置,即使是显式设置type='linear'
(默认设置)scheme=
也会被忽略。这是一个错误吗?如果不是,我如何以一种有意义的方式理解配色方案的使用?如果我不能直接使用方案,我如何检查方案并提取其颜色值以重复使用?
这里有些例子:
import numpy as np
import pandas as pd
import altair as alt
# This question is about Altair - plotnine is only here for the example data
from plotnine.data import diamonds
# This works, and gives me the greenblue color scheme:
alt.Chart(diamonds).mark_rect().encode(
x=alt.X('carat',bin=True),
y=alt.Y('price',bin=True),
color=alt.Color('count()',scale=alt.Scale(scheme='greenblue'))
)
# This gives me a log scale, but now the greenblue scheme is gone:
alt.Chart(diamonds).mark_rect().encode(
x=alt.X('carat',bin=True),
y=alt.Y('price',bin=True),
color=alt.Color('count()',scale=alt.Scale(type='log',scheme='greenblue'))
)
# Direct specification of range works, but it is not exactly the same
# colors as greenblue. If this is the only way to do it, how do I open
# up the greenblue scheme and grab its colors?
alt.Chart(diamonds).mark_rect().encode(
x=alt.X('carat',bin=True),
y=alt.Y('price',bin=True),
color=alt.Color('count()',scale=alt.Scale(type='log',range=['palegreen','blue']))
)