[英]how to add box plot to scatter data in matplotlib
我有以下數據,在繪制散點數據點后,我想在每組位置周圍添加boxplot。 這是我繪制散點圖的代碼:
%matplotlib inline
import matplotlib.pyplot as plt
X = [1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8,
9, 9, 9, 9, 9, 9, 9,
10, 10, 10, 10, 10, 10, 10,
11, 11, 11, 11, 11, 11, 11,
12, 12, 12, 12, 12, 12, 12,
13, 13, 13, 13, 13, 13, 13,
14, 14, 14, 14, 14, 14, 14,
15, 15, 15, 15, 15, 15, 15]
H = [15, 17, 16, 20, 15, 18, 15,
17, 16, 16, 20, 19, 18, 15,
20, 22, 20, 22, 19, 21, 21,
19, 21, 20, 23, 21, 20, 22,
21, 23, 22, 20, 24, 22, 20,
20, 19, 20, 18, 21, 17, 19,
18, 20, 16, 15, 17, 20, 19,
19, 19, 18, 21, 21, 16, 19,
21, 22, 22, 24, 24, 23, 25,
28, 26, 30, 27, 26, 29, 30,
27, 26, 29, 31, 27, 29, 30,
25, 26, 27, 28, 25, 27, 30,
31, 28, 25, 27, 30, 25, 31,
28, 26, 30, 28, 29, 27, 31,
24, 26, 25, 28, 26, 23, 25]
fig, axes = plt.subplots(figsize=(8,5))
axes.scatter(X, H, color='b')
axes.set_xlabel('Pos');
axes.set_ylabel('H, µm');
當我添加plt.boxplot時,它將捕獲所有數據,而不是單個位置。 我對matplotlib或seaborn中的答案表示贊賞。
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.