すでについているtiitoiさんとmagichanさんの回答は、十分エレガントな解決策になっています。
しかし、あえてPyplotインターフェースでやる。
python
1import numpy as np
2import matplotlib.pyplot as plt
3
4t = np.arange(0.0, 5.0, 0.1)
5
6#Fig1 サブプロット作成
7y11 = np.exp(-t) * np.cos(2*np.pi*t)
8fig1=plt.figure()
9plt.subplot(121)
10plt.plot(t, y11, 'b-')
11
12#Fig2 サブプロット作成
13y21 = 2*t
14fig2=plt.figure()
15plt.subplot(121)
16plt.plot(t, y21, 'r-')
17
18## 追加したもの
19# current figure切り替え
20plt.figure(fig1.number)
21
22#Fig1へサブプロット追加したい
23y12 = np.exp(-t) * np.cos(4*np.pi*t)
24fig1.add_subplot(122)
25plt.plot(t, y12, 'b-')
26
27plt.show()
できる根拠:
num : integer or string, optional, default: None
If not provided, a new figure will be created, and the figure number will be incremented. The figure objects holds this number in a number attribute. If num is provided, and a figure with this id already exists, make it active, and returns a reference to it. If this figure does not exists, create it and returns it. If num is a string, the window title will be set to this figure's num.
matplotlib.pyplot.figure — Matplotlib 3.1.2 documentation
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。