Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue using qualitative brewer palettes in plotnine

I would like to use a brewer qualitative palette using plotnine, but I get the error:

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']

Reproducible example

 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'))

In ggplot2 in R, however, you can do the same and get the correct plot

 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")
like image 749
jcp Avatar asked Mar 28 '18 10:03

jcp


1 Answers

You have to include the "type" argument

scale_fill_brewer(type="qual", palette="Set1")
like image 109
Xavaar Quaranto Avatar answered Nov 03 '22 05:11

Xavaar Quaranto