'Make Seaborn Distplot and Barplot the same color [duplicate]
I have been unable to figure out how to set the colors between distplot and barplot to be the same. Despite setting the color argument in both functions to "blue", they are clearly different shades and I would like them to be the same. Any help would be great as I would like consistency in the project I am working on.
Solution 1:[1]
The default "blue" for the tow plotting function is different. For seaborn, you can extract the color in this way:
pal = sns.color_palette("Blues")
print(pal.as_hex())
['#dbe9f6', '#bad6eb', '#89bedc', '#539ecd', '#2b7bba', '#0b559f']
Not sure which blue you might be referring to, but by passing the hex value to matplotlib, you can ensure that they have the same color.
Solution 2:[2]
You could use palette
instead of color
import seaborn as sns
import matplotlib.pyplot as plt
# some dummy data
x = ['A', 'B', 'C', 'D']
y = [2, 4, 11, 6]
n_bins = len(x)
# If you want all four of your bins to be 'royalblue' color.
palette = ['royalblue'] * n_bins
# all four bars are the same color.
sns.barplot(x, y, palette=palette)
plt.show()
Now if you want all of your barplots
to have the same colored bars, you can keep using the same palette
.
Warning: sns.distplot
is deprecated as of seaborn 0.11.2
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 | TYZ |
Solution 2 |