Issue using qualitative brewer palettes in plotnine
Asked Answered
P

1

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")
Phytogenesis answered 28/3, 2018 at 10:6 Comment(6)
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'))Oat
Yes, Blues works, but it is a sequential scale. I would like to use a qualitative one.Phytogenesis
The error message says ValueError: Invalid color map name 'Set1' for type 'Sequential' - if scale_color_brewer() expects Sequential then forget about other values.Trilobite
The point is that it shouldn't expect Sequential. Please see my edited question and added a ggplot2 code that produces what I expected.Phytogenesis
Have you tried passing type argument as stated in ropensci.github.io/plotly/ggplot2/scale_brewer.html ?Trilobite
No, I hadn't... that was the mistake. Thanks!Phytogenesis
H
4

You have to include the "type" argument

scale_fill_brewer(type="qual", palette="Set1")
Hattiehatton answered 12/2, 2021 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.