Reputation: 153
I am trying to change the usual Boxplot outlier shape (the jitter above the boxes) which is a circle by default to a diamond. I am using the following code so far:
import pandas as pd
import matplotlib.pyplot as plt
box = plt.boxplot([x1, x2], labels = ["Var1_Name",
"Var2_Name"], notch=True, patch_artist=True)
Is there a way to make this change?
Upvotes: 6
Views: 9014
Reputation: 174
On top of JohanC's answer, I personally prefer this way:
import matplotlib.pyplot as plt
box = plt.boxplot([[1,5,6,7,6,10],[1,4,5,5,6,10]],patch_artist=True)
widths = [1,3]
styles = ['*','D']
for n,f in enumerate(box['fliers']):
f.set(markeredgewidth=widths[n],marker=styles[n])
It will give you the results below:
Upvotes: 0
Reputation: 80329
You can change the properties of the fliers via flierprops
:
import matplotlib.pyplot as plt
import numpy as np
box = plt.boxplot([np.random.randn(200), np.random.randn(200)], labels=["Var1_Name", "Var2_Name"],
notch=True, patch_artist=True,
flierprops={'marker': 'o', 'markersize': 10, 'markerfacecolor': 'fuchsia'})
To only change the symbol, you can leave out flierprops=
and just use sym='*'
. If, on the contrary, you need more control or need their exact positions, the fliers are also returned by box = plt.boxplot(...)
as box['fliers']
.
Upvotes: 10