我想使用plotnine使用brewer定性调色板,但我收到错误:
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")
答案 0 :(得分:1)
您必须包含“类型”参数
scale_fill_brewer(type="qual", palette="Set1")