[英]Matplotlib doesn't forget previous data when saving figures with savefig
What you see is a completely expected behaviour. 您看到的是完全预期的行为。 You can plot as many data as often as you want to the same figure, which is very often very useful.
您可以在同一图形上绘制任意数量的数据,这通常非常有用。
If you want to create several figures in the same script using the matplotlib state machine, you need to first close one figure before generating the next. 如果要使用matplotlib状态机在同一脚本中创建多个图形,则需要先关闭一个图形,然后再生成下一个图形。
So in this very simple case, just add plt.close()
between figure creation. 因此,在这种非常简单的情况下,只需在图形创建之间添加
plt.close()
。
import matplotlib.pyplot as plt
plt.plot([1,2,3],[1,2,3],'bo')
plt.axis([-4,4,-4,4])
plt.savefig('azul.png')
plt.close()
plt.plot([0,1,2],[0,0,0],'yo')
plt.axis([-4,4,-4,4])
plt.savefig('amarillo.png')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.