'Matplotlib: connect medians of boxplots with a line [duplicate]
I would like to have a line connecting the medians or means of my boxplots. I use matplotlib.
Is there any way to achieve this easily?
import matplotlib.pyplot as plt, numpy as np, seaborn as sns
np.random.seed(0)
plt.style.use('default')
X = list()
X1 = np.random.rand(10).tolist()
X2 = np.random.rand(10).tolist()
X3 = np.random.rand(10).tolist()
X4 = np.random.rand(10).tolist()
X.append(X1)
X.append(X2)
X.append(X3)
X.append(X4)
plt.figure(dpi=120)
bplot = plt.boxplot(X, patch_artist=True, showmeans=True)
plt.xticks(range(1,5), ["1","2","3","4"])
sns.despine(top=True, right=True, left=False, bottom=False)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|