Matplotlib提供以下功能:
cla() # Clear axis
clf() # Clear figure
close() # Close a figure window
Run Code Online (Sandbox Code Playgroud)
该文档没有提供很多关于这些功能之间的区别的见解.我什么时候应该使用每个功能,它究竟做了什么?
你如何matplotlib.pyplot"忘记"以前的情节
我试图多次使用 matplotlib.pyplot
代码如下所示:
def plottest():
import numpy as np
import matplotlib.pyplot as plt
a=np.random.rand(10,)
b=np.random.rand(10,)
c=np.random.rand(10,)
plt.plot(a,label='a')
plt.plot(b,label='b')
plt.plot(c,label='c')
plt.legend(loc='upper left')
plt.ylabel('mag')
plt.xlabel('element)')
plt.show()
e=np.random.rand(10,)
f=np.random.rand(10,)
g=np.random.rand(10,)
plt.plot(e,label='e')
plt.plot(f,label='f')
plt.plot(g,label='g')
plt.legend(loc='upper left')
plt.ylabel('mag')
plt.xlabel('element)')
plt.show()
Run Code Online (Sandbox Code Playgroud)
不幸的是,无论我做什么,我都会得到相同的情节(实际上来自我之前运行和完成的其他代码).
类似的代码以前对我有效.
我看过这些问题:
Matplotlib pyplot show()一旦关闭就不起作用
(python)matplotlib pyplot show()..阻塞与否?
并尝试使用plt.show(),plt.clf()并plt.close无济于事.
有任何想法吗?