Ter*_*ian 7 python numpy altair
我是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']))
)
Run Code Online (Sandbox Code Playgroud)
我想这一定是一个错误。我在 github 上找不到修复此行为的问题,但您发布的代码现在似乎按预期工作。我正在运行 atair 版本'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'))
)
Run Code Online (Sandbox Code Playgroud)
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'))
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
539 次 |
| 最近记录: |