-
Notifications
You must be signed in to change notification settings - Fork 241
Closed
Labels
Description
Greetings,
I was puzzled by this on a recent plot. Here's a reproducible example:
import pandas as pd
import random
from plotnine import *
random.seed(1)
df = pd.DataFrame({'x': [random.randrange(100) for _ in range(100)],
'y': [random.randrange(100) for _ in range(100)],
'c': [random.randrange(5) for _ in range(100)]})
p = ggplot(df, aes(x='x', y='y', color='c')) + geom_point()
p
By default, we get a viridis continous color scale:

I wanted to change the name, so I added this line:
p = ggplot(df, aes(x='x', y='y', color='c')) + geom_point()
p = p + scale_color_continuous(name='foo')
p
I got this error instead:
ValueError: 'foo' is not a valid value for name; supported values are [list of color palette names]
For some silly reason I thought to try the european R ggplot spelling instead, which works but changes the color scale...
p = ggplot(df, aes(x='x', y='y', color='c')) + geom_point()
p = p + scale_colour_continuous(name='foo')
p
How can I have both a viridis palette and a custom scale name? I'm sure this is something trivial I'm overlooking, but I haven't figured it out! Many thanks.
