如何在同一窗口中同时显示和更新两个matplotlib图? (第2部分)

时间:2018-06-21 02:32:54

标签: python matplotlib

此问题的继续:How can I display and update two matplotlib plots in the same window at the same time?

先前的解决方案并未解决所有地块更新问题。尽管在使用tight_layout()时可以用self.comparison_figure1替换“ plt”,但是在使用cla()清除图时,则无法完成此操作。结果,当我从下拉菜单中选择其他选项时,我的第二张图将被清除和更新,但是不会清除和更新第一张图,因为“ plt”不再引用第一张图。

我使用cla()的代码部分:

sns.set(style="whitegrid")
plt.cla()
ax = self.comparison_figure2.add_subplot(111)
.....

如果需要,我可以发布更多代码!

2 个答案:

答案 0 :(得分:0)

cla()用于清除轴,不能与图形一起使用。

clf()用于清除图形。

所以代替:

plt.cla()

使用:

figure.clf()

答案 1 :(得分:0)

cla

cla() cl 会出现 a 个。与plt.cla()等效的是

ax.cla()
# or
ax.clear()

,其中ax是特定的matplotlib.axes.Axes

clf

clf cl 显示 f 图。与plt.clf()等效的是

fig.clf()
# or
fig.clear()

其中figmatplotlib.figure.Figure