Simple question that I cannot seem to find the answer to.
How do I change the color and shape of the mean indicator in a Seaborn Boxplot?
It defaults to a Green Triangle and it generally difficult to see.
I've tried to find the answer in both the seaborn documentation, as well as the matplotlib documentation. There is also a related question on stackoverflow where someone asked how to change around colors related to the seaborn boxplots and was able to change everything except for the mean indicator.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
data = [[np.random.rand(100)] for i in range(3)]
sns.boxplot(data=data, showmeans=True)
plt.show()
1) Using predefined palettes of seaborn This can be done by adding a palette argument inside the boxplot() function and giving it any predefined seaborn color palette value like “Set1”, “Set2”, “Paired”, “Set3” etc.
To show mean in a box plot, we can use showmeans=True in the argument of boxplot() method.
In seaborn, the hue parameter determines which column in the data frame should be used for colour encoding. Using the official document for lmplot provided an example for this.
The keyword argument you are looking for is meanprops
. It is in the matplotlib boxplot documentation under "other parameters":
import seaborn as sns
data = [[np.random.rand(100)] for i in range(3)]
sns.boxplot(data=data, showmeans=True,
meanprops={"marker":"s","markerfacecolor":"white", "markeredgecolor":"blue"})
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With