I have a dataframe with animal names in it, like:-
cat
dog
pig
lion
tiger
goat
dog
dog
goat
pig
cat
lion
I want to draw a horizontal bar graph using:-
c=['green','pink','blue','yellow','cyan','teal','red','violet']
df.animal.value_counts().sort_values().plot(kind='barh', color=c, alpha=0.5)
This works well.
But every time count of the animal changes the colour for that bar changes.
I want to have a consistent colour for an animal, say "blue" for "cat" and "green" for "dog" and so on. How do I do this?
This dataset is continuously evolving and can have newer animals names with time and I wish to ensure that a new colour is automatically assigned to an animal as it gets added. Even if this cannot be done I would be grateful if you can help with the initial request.
I tried various options as found on StackOverflow and otherwise but am not getting what I want.