擅长:python、mysql、java
<p>简化后,<code>plt.show()</code>将启动一个事件循环,并为在<code>pyplot</code>状态内活动的每个图形创建一个图形表示。你知道吗</p>
<p>相反,<code>fig.show()</code>,其中<code>fig</code>是一个figure实例,将只显示这个figure。因为它也不会阻塞,所以它(仅)在交互式会话中有用;否则,由于脚本退出,在显示该图之后,该图将直接关闭。你知道吗</p>
<p>因此,在通常情况下,您更喜欢<code>plt.show()</code>。这并不妨碍您使用面向对象接口。因此,创建和显示图形的推荐方法是</p>
<pre><code>import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(x, y)
plt.show()
</code></pre>
<p>对于两个窗口,你可以重复绘图</p>
<pre><code>import matplotlib.pyplot as plt
fig1, ax1 = plt.subplots()
ax1.plot(x1, y1)
fig2, ax2 = plt.subplots()
ax2.plot(x2, y2)
plt.show()
</code></pre>