我有这个代码:
import matplotlib.pyplot as plt
import numpy as np
dat=[0,40]
fig = plt.figure()
ax = fig.add_subplot(111)
ax2 = fig.add_subplot(211)
Ln, = ax.plot(dat)
Ln2, = ax2.plot(dat)
plt.ion()
plt.show()
x, xx = [], []
for i in range(20):
x.append(i / 2)
xx = [np.cos(a) for a in x[-10:]]
x.extend(xx)
ax.set_xlim(0, len(x)+5)
ax.set_ylim(min(x), max(x)+5)
Ln.set_ydata(x)
Ln.set_xdata(range(len(x)))
x = x[:-len(xx)]
ax2.set_xlim(0, len(x)+5)
ax2.set_ylim(min(x), max(x)+5)
Ln2.set_ydata(x)
Ln2.set_xdata(range(len(x)))
plt.pause(0.5)
如果你运行它,你会看到:
- 那
ax2
是向上的,而它应该在下面。 - 每个子图如何相互重叠。
我希望它更“好看”,但我已经搜索过了,我只是不知道从哪里开始。感谢您的帮助!