1 | initial version |
To create a box plot in Matplotlib that includes two summary statistics, you can follow the steps below:
import matplotlib.pyplot as plt
import numpy as np
data1 = np.random.normal(50, 10, 100)
data2 = np.random.normal(70, 5, 100)
data = [data1, data2]
labels = ['Dataset 1', 'Dataset 2']
boxplot()
function:fig, ax = plt.subplots()
ax.boxplot(data, vert=False, labels=labels, showmeans=True, meanline=True)
Here, vert=False
makes the plot horizontal, labels
adds the labels we created in step 4, showmeans=True
and meanline=True
show the mean values and a line indicating the mean.
plt.show()
This will create a box plot with two datasets, labeled and with the mean values shown.