matpltlib报错:
MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
self.axes = self.fig.add_subplot(111) # 建立一个子图
原因是重复添加子图,例如,已经使用 self.axes = self.fig.add_subplot(111)
添加了一个子图,再重复添加即报错。
把figure的子图先删了,再重新添加。其中clear()是figure类的方法。示例(以下均在类里面做的示例):
self.fig = plt.figure()
self.axes = self.fig.add_subplot(111) # 建立一个子图
self.fig.clear() # 先清除子图
self.axes = self.fig.add_subplot(111) # 建立一个子图