我想使用plotnine使用酿酒师定性调色板,但我得到了错误:
ValueError: Invalid color map name 'Set1' for type 'Sequential'.
Valid names are: ['Blues', 'BuGn', 'BuPu', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']
可重复的示例
from plotnine import *
import pandas as pd
df = pd.DataFrame({'a': [0,1,2,3,4], 'b': [0,-2,10,6,8], 'c': ['a', 'b', 'a', 'a', 'b']})
(ggplot(df, aes(x = 'a', y = 'b', color = 'factor(c)')) +
geom_line() +
scale_color_brewer(palette = 'Set1'))
在r中的ggplot2中,您可以执行相同的操作并获得正确的图
library(ggplot2)
df = data.frame(a = c(0,1,2,3,4), b = c(0,-2,10,6,8), c = c('a', 'b', 'a', 'a', 'b'))
ggplot(df, aes(x = a, y = b, color = factor(c))) +
geom_line() +
scale_color_brewer(palette = "Set1")
您必须包括"类型"。参数
scale_fill_brewer(type="qual", palette="Set1")