相关疑难解决方法(0)

何时使用cla(),clf()或close()清除matplotlib中的图?

Matplotlib提供以下功能:

cla()   # Clear axis
clf()   # Clear figure
close() # Close a figure window
Run Code Online (Sandbox Code Playgroud)

该文档没有提供很多关于这些功能之间的区别的见解.我什么时候应该使用每个功能,它究竟做了什么?

plot matplotlib

492
推荐指数
3
解决办法
62万
查看次数

matplotlib.pyplot不会忘记以前的情节 - 如何刷新/刷新?

你如何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无济于事.

有任何想法吗?

python matplotlib

71
推荐指数
2
解决办法
9万
查看次数

标签 统计

matplotlib ×2

plot ×1

python ×1