'Seaborn: How to change the color of individual bars in histogram?

I was looking on internet but i didn't get any solution.

I have this graph and I want to change the color of the first bar, if I use the parameter 'color' it changes all the bars.

seaborn graph

Is it possible to do this? Thank u so much!



Solution 1:[1]

Use:

import seaborn as sns
s = [1,1,2,2,1,3,4]
s = pd.DataFrame({'val': s, 'col':['1' if x==1 else '0' for x in s]})
sns.histplot(data=s, x="val", hue="col")

The output:

enter image description here

Solution 2:[2]

Well, the exact way will depend on which mapping software you are using. Your best bet is to break your data into two sets, one for the first bar and one for the rest. You should be able to output each of the sets in its own colour.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 keramat
Solution 2 William