Python 如何在不重叠数据的情况下在for循环中保存多个绘图?
我在for循环的每次迭代中都会保存图,但由于某种原因,在第一个图之后,其余的图是重叠的,因此我可以在最后一个图上看到所有以前的图都重叠了 我使用以下函数来保存绘图Python 如何在不重叠数据的情况下在for循环中保存多个绘图?,python,matplotlib,Python,Matplotlib,我在for循环的每次迭代中都会保存图,但由于某种原因,在第一个图之后,其余的图是重叠的,因此我可以在最后一个图上看到所有以前的图都重叠了 我使用以下函数来保存绘图 def plotStats(aggr_ep_rewards, i, my_file): '''Plot rewards curves''' DIR = '../Simulations/2_Q_Learning_exploration_explotation/A/' plt.plot(aggr_ep_rewa
def plotStats(aggr_ep_rewards, i, my_file):
'''Plot rewards curves'''
DIR = '../Simulations/2_Q_Learning_exploration_explotation/A/'
plt.plot(aggr_ep_rewards['ep'], aggr_ep_rewards['avg'])#label="average rewards"
plt.legend(loc=4)
plt.title(f"RL Q_Learning TEST:{i}")
plt.xlabel('Episodes')
plt.ylabel('Rewards')
# plt.show()
plt.savefig(os.path.join(DIR, my_file))
我错过什么了吗?如何为每次迭代获取单独的图形?在调用
plt.plot
之前尝试使用plt.figure()
,非常感谢,就这样!!!!