Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to change the color and shape indicating the mean in a seaborn boxplot?

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()

Seaborn Boxplot

like image 652
Christopher James Avatar asked Jan 10 '19 16:01

Christopher James


People also ask

How do you change the color of a boxplot in Seaborn?

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.

How do you show the mean on a boxplot in Python?

To show mean in a box plot, we can use showmeans=True in the argument of boxplot() method.

What is hue in Seaborn boxplot?

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.


1 Answers

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()

enter image description here

like image 169
DavidG Avatar answered Sep 28 '22 02:09

DavidG