【发布时间】:2019-03-25 04:00:10
【问题描述】:
我是 Altair 的新手,我正在尝试制作一个带有对数刻度颜色的热图,并且还选择了一个非默认配色方案(默认方案使用的范围非常小,而且我想要 light-to -暗色)。我发现使用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']))
)
【问题讨论】: