2

I have a dataframe "table" like this:

SAMPLE RANK VALUE CAT 3 N DOG 1 N FISH 4 Y ANT 2 N HORSE 5 N

How can I JUST COLOR the 3rd histogram column, given that there is a "Y" in the VALUE column? I would like it to look like this:

So far I have :

table.plot('SAMPLE','RANK', hue="VALUE", palette={"Y": "r", "N": '0.75'}, kind='bar')

but this does not work

enter image description here

amc
  • 813
  • 1
  • 15
  • 28

1 Answers1

5

You may achieve the desired effect by mapping VALUE column to desired colors:

colors = {'N':'#00BEC5', 'Y':'#F9746A'}
df.sort_values('RANK', inplace=True)
df.plot.bar(x='SAMPLE', y='RANK',color= df['VALUE'].map(colors));

enter image description here

Sergey Bushmanov
  • 23,310
  • 7
  • 53
  • 72