我是Altair的新手,我正在尝试制作一个对数色标的热图,并选择一个非默认的配色方案(默认方案使用的范围很小,我也想要浅到暗的颜色)。我发现使用type=log
可以很容易地获得对数刻度,但是一旦我这样做了,scheme=
参数就会被忽略。如果我用range=
手动设置高和低颜色,效果会很好。
我进一步发现,如果我以任何方式显式设置type=
,即使是显式设置type='linear'
(这是默认设置),scheme=
也会被忽略。这是一个bug吗?如果没有,我如何才能理解配色方案的使用,才能让这一切变得有意义呢?如果我不能直接使用方案,我如何检查该方案并提取其颜色值以供重用?
下面是一些示例:
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']))
)
发布于 2019-10-25 16:25:55
我想这一定是个bug。我在github上找不到这个问题,这个问题已经被修复了,但是你发布的代码现在似乎可以正常工作了。我运行的是阿泰尔版本的'3.2.0'
。
import numpy as np
import pandas as pd
import altair as alt
from plotnine.data import diamonds
# Added to alleviate the large dataset issues
alt.data_transformers.enable('json')
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'))
)
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'))
)
https://stackoverflow.com/questions/52906275
复制相似问题