答案 0 :(得分:1)
方法add_subplot
在图上创建一个Axes对象,该对象被调用。
您在fig
上调用两次,因此请获取相同的Axes对象。
请尝试:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
fig_norm = plt.figure()
fig.show()
fig_norm.show()
ax_fig = fig.add_subplot(1, 1, 1)
ax_fig_norm = fig_norm.add_subplot(1, 1, 1)
ax_fig.set_title("Figure 1", fontsize='large')
ax_fig_norm.set_title("Figure Normalized", fontsize='large')
plt.ion()
while True:
x = np.random.rand(100)
y = np.random.rand(100)
ax_fig.plot(x, y)
ax_fig_norm.plot(x*3, y*3)
fig.canvas.draw()
fig_norm.canvas.draw()