回答編集履歴

1

d

2018/11/10 14:50

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -47,3 +47,51 @@
47
47
 
48
48
 
49
49
  ![イメージ説明](9b40c2526068b7fdf8d5f1f587300452.png)
50
+
51
+
52
+
53
+ ## すべての Axes で凡例を共有する場合
54
+
55
+
56
+
57
+ Figure.legend() を呼べばよいです。
58
+
59
+ 位置の指定などは引数でできるので、[matplotlib.pyplot.legend()](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.legend.html) を参照してください。
60
+
61
+
62
+
63
+ ```python
64
+
65
+ import matplotlib.pyplot as plt
66
+
67
+
68
+
69
+ t = [0,1,2,3]
70
+
71
+ x0 = [2,4,6,8]
72
+
73
+ x1 = [4,6,8,10]
74
+
75
+ x2 = [6,8,10,12]
76
+
77
+
78
+
79
+ fig, [axL, axC, axR] = plt.subplots(ncols=3, figsize=(10,4))
80
+
81
+ axL.plot(t, x0, linewidth=2, label="X0")
82
+
83
+ axC.plot(t, x1, linewidth=2, label="X1")
84
+
85
+ axR.plot(t, x2, linewidth=2, label="X2")
86
+
87
+ fig.legend(loc='upper right')
88
+
89
+
90
+
91
+ plt.show()
92
+
93
+ ```
94
+
95
+
96
+
97
+ ![イメージ説明](3ec66a46d3d735fe31affefff09d2b2b.png)