我制作了多个图并将其保存,图像不仅包括当前图,还包括之前的所有图如何解决?

问题描述

我需要进行一系列绘制并将其保存在目录中。使用for循环,在每次迭代中,我都会创建一个新图并使用savefig保存它。代码如下-

def find_posterior(prior_a: int,prior_b: int,input_file: TextIO):
    a = prior_a
    b = prior_b
    
    #the x values required
    x = list(np.arange(0.01,1,0.02))
    
    #image number
    img = 0

    for value in input_file:
        #empty the values of the beta function
        y = []
        
        #update the prior to the posterior based on the value of the toss
        toss = int(value.strip())
        if(toss == 1):
            a = a + 1
        else:
            b = b + 1

        #get the values of the beta function in y for values over x
        beta_plot_values(a,b,x,y)
        #plot the posterior function
        plt.plot(x,y)
        
        #save it in the images folder
        img = img + 1
        file_name = 'images\img' + str(img) + '.png'
        plt.savefig(file_name)

但是,当我查看保存在目录中的图像时,每个图像也包含在其之前创建的所有图形。

enter image description here

我该如何解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...