问题描述
我需要进行一系列绘制并将其保存在目录中。使用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)
但是,当我查看保存在目录中的图像时,每个图像也包含在其之前创建的所有图形。 我该如何解决?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)