7

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")
jcp
  • 749
  • 6
  • 21
  • In the error it says that 'Set1' is invalid, have you tried one of the valid ones (like "Blues")? as `scale_color_brewer(palette = 'Blues'))` – Ale Mar 28 '18 at 10:14
  • Yes, Blues works, but it is a sequential scale. I would like to use a qualitative one. – jcp Mar 28 '18 at 10:18
  • The error message says `ValueError: Invalid color map name 'Set1' for type 'Sequential'` - if `scale_color_brewer()` expects `Sequential` then forget about other values. – ElmoVanKielmo Mar 28 '18 at 10:43
  • The point is that it shouldn't expect `Sequential`. Please see my edited question and added a `ggplot2` code that produces what I expected. – jcp Mar 28 '18 at 10:53
  • 3
    Have you tried passing `type` argument as stated in https://ropensci.github.io/plotly/ggplot2/scale_brewer.html ? – ElmoVanKielmo Mar 28 '18 at 11:12
  • No, I hadn't... that was the mistake. Thanks! – jcp Mar 28 '18 at 14:50

1 Answers1

4

You have to include the "type" argument

scale_fill_brewer(type="qual", palette="Set1")