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?
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']
.