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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-08-23 11:00:00 +0000
Seen: 9 times
Last updated: Nov 03 '22
The mplfinance plot displays accurately, but the datetime format is unusual.
How can the black color be modified in Seaborn boxplots?
How can I modify the arrow axes and their tick labels in a Matplotlib plot?
What is the procedure for incorporating superscript in a forest.meta plot?
How to create a plot using mplfinance and PyQt5 that includes a volume graph?
What is the process for creating a set of vertical lines using gnuplot?
In sagemath, what is the procedure for plotting vector functions?
How can the clipping of objects in matplotlib 3D be modified?
How can a histogram plot in a Pandas dataframe be transformed into a scatter plot?