如何在matplotlib中分别显示数字? [英] How can I show figures separately in matplotlib?
本文介绍了如何在matplotlib中分别显示数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在matplotlib中有两个图形,每个图形有一个图形:
Say that I have two figures in matplotlib, with one plot per figure:
import matplotlib.pyplot as plt
f1 = plt.figure()
plt.plot(range(0,10))
f2 = plt.figure()
plt.plot(range(10,20))
然后我一次展示两个
plt.show()
是否可以单独显示它们,即仅显示f1
?
Is there a way to show them separately, i.e. to show just f1
?
或更妙的是:如何像下面一厢情愿"的代码(不能正常工作)那样分别管理这些数字:
Or better: how can I manage the figures separately like in the following 'wishful' code (that doesn't work):
f1 = plt.figure()
f1.plot(range(0,10))
f1.show()
推荐答案
好的.使用add_subplot
添加Axes
. (编辑import
.)(编辑show
.)
Sure. Add an Axes
using add_subplot
. (Edited import
.) (Edited show
.)
import matplotlib.pyplot as plt
f1 = plt.figure()
f2 = plt.figure()
ax1 = f1.add_subplot(111)
ax1.plot(range(0,10))
ax2 = f2.add_subplot(111)
ax2.plot(range(10,20))
plt.show()
或者,使用add_axes
.
ax1 = f1.add_axes([0.1,0.1,0.8,0.8])
ax1.plot(range(0,10))
ax2 = f2.add_axes([0.1,0.1,0.8,0.8])
ax2.plot(range(10,20))
这篇关于如何在matplotlib中分别显示数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文