Reputation: 1239
I would like to move the x-axis to the top of my plot and manually fill the colors. However, the usual method in ggplot does not work in plotnine. When I provide the position='top'
in my scale_x_continuous()
I receive the warning: PlotnineWarning: scale_x_continuous could not recognize parameter 'position'.
I understand position is not in plotnine's scale_x_continuous, but what is the replacement? Also, scale_fill_manual()
results in an Invalid RGBA argument: 'color'
error. Specifically, the value
requires an array-like object. Thus I provided the array of colors, but still had an issue. How do I manually set the colors for a scale_fill object?
import pandas as pd
from plotnine import *
lst = [[1,1,'a'],[2,2,'a'],[3,3,'a'],[4,4,'b'],[5,5,'b']]
df = pd.DataFrame(lst, columns =['xx', 'yy','lbls'])
fill_clrs = {'a': 'goldenrod1',
'b': 'darkslategray3'}
ggplot()+\
geom_tile(aes(x='xx', y='yy', fill = 'lbls'), df) +\
geom_text(aes(x='xx', y='yy', label='lbls'),df, color='white')+\
scale_x_continuous(expand=(0,0), position = "top")+\
scale_fill_manual(values = np.array(list(fill_clrs.values())))
Upvotes: 3
Views: 1680
Reputation: 2375
Plotnine does not support changing the position of any axis.
You can pass a list
or a dict
of colour values to scale_fill_manual
provided they are recognisable colour names. The colours you have are obscure and they are not recognised. To see that it works try 'red' and 'green', see https://matplotlib.org/gallery/color/named_colors.html for all the named colors. Otherwise, you can also use hex colors e.g. #ff00cc.
Upvotes: 4