それで、クラス Pendulum 内に plot を呼び出す関数 plot(self) があるとします。次に、同じクラス Pendulum 内に別の関数 plot2(self) があり、これも plot を呼び出します。両方の関数が複数のグラフを同じ図の個別のサブプロットとして設定するように pyplot を設定するにはどうすればよいですか?
1 に答える
1
これを試して:
import numpy as np
import matplotlib.pyplot as plt
class Pendulum:
def __init__(self):
self.fig = plt.figure()
def plot1(self):
ax = self.fig.add_subplot(211)
ax.plot([1,2],[3,4])
def plot2(self):
ax = self.fig.add_subplot(212)
ax.plot([1,2],[4,3])
p = Pendulum()
p.plot1()
p.plot2()
plt.show()
于 2012-11-16T01:48:01.483 に答える