Issue
I inserted the following code into a for-loop:
for code in list_code:
.....
sns.lineplot(original['Date'], original['Open'])
sns.lineplot(df_forecast['Date'], df_forecast['Open'])
plt.savefig(f"output_{code}.png")
The first iteration, there were only 2 lines (correct).
In the second iteration, the 2 lines from the first iteration were also added to the image,
so that I now had 4 lines instead of only 2 lines.
After the last iterations, there were so many lines (I only need 2 lines per image). How can I run the for-loop without the lines from the previous iterations being included?
Solution
You can just plt.cla()
after saving the figure.
This will clear your current axes
Answered By - Lior Cohen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.