1. 导包
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['font.sans-serif'] = "SimHei"
plt.rcParams["axes.unicode_minus"] = False
%config Inlinebackend.figure_format = "svg"
2. 箱型图
x = [1, 2, 3, 5, 7, 9, 20, -10]
plt.boxplot(x)
plt.show()
3. 一次画多个箱型图
x1 = np.random.randint(10, 100, 100)
x2 = np.random.randint(10, 100, 100)
x3 = np.random.randint(10, 100, 100)
plt.boxplot([x1, x2, x3])
plt.show()
data = np.random.normal(size=(500, 4))
data
array([[-0.73374384, 0.63175711, 1.04054883, -0.43242146],
[-0.28473971, -0.92793591, 0.43866245, 1.900678 ],
[-0.89522388, -1.16235456, -1.12767215, 1.53754262],
...,
[-0.29056696, -0.46957062, 0.51633617, -2.18227425],
[-0.39322918, 0.17550912, -0.36366539, -2.10251157],
[-1.26435622, -1.16706424, 0.69153696, -0.34231218]])
labels = ["A", "B", "C", "D"]
plt.boxplot(data, labels=labels, notch=True, sym="r*")
plt.show()