2

I am trying to plot a histogram with a color scale from blue to white.

gg = pd.DataFrame()
gg['x'] = u
p = ggplot(aes(x='x'),gg) + 
geom_histogram(aes(fill='..count..'),binwidth=0.1)
p = p + scale_color_gradient(low='blue',high='white')
print(p)

If I comment out the scale_color_gradient line everything works with the default color scheme.

However, if I run the code above as is, I get the message:

UserWarning: Cannot generate legend for the 'color' aesthetic. Make sure you have mapped a variable to it "variable to it".format(output))

I have searched the documentation and examples but didn't find how to map the variable to the color scale.

Does anyone know how to do this?

Thanks

bill fite
  • 43
  • 5

1 Answers1

0

You mapped to the fill aesthetic with fill='..count', so you should use scale_fill_gradient.

has2k1
  • 2,095
  • 18
  • 16