Python(Matplotlib/seaborn) – way to build a barplot with color being a key of a third variable?


This Content is from Stack Overflow. Question asked by sammyp

Working with the following dataframe:
d={‘Country’:[‘Iraq’, ‘Pakistan’, ‘Afghanistan’, ‘Colombia’, ‘Turkey’], ‘Region’:[‘Middle East’, ‘Asia’, ‘Asia’, ‘South America’, ‘Middle East’], ‘Count’:[‘2400’, ‘1400’, ‘1200’, ‘800’, ‘420’]}
Is there a way to plot Country against Count with the colour of each bar being keyed to their respective region?
e.g. Iraq and Turkey being Red while Pakistan and Afghanistan being Blue etc..


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?