[Solved] Matplotlib ERROR: MatplotlibDeprecationWarning: Adding an axes using the same arguments…

Matplotlib error: MatplotlibDeprecationWarning: Adding an axes using the same arguments…
matpltlib error:

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)  # Create a subgraph

The reason is to add subgraphs repeatedly, for example, self.axes = self.fig.add has been used_ Subplot (111) adds a subgraph, and then adds it repeatedly to report an error.

Solution:

Delete the subgraph of figure and add it again. Clear() is the method of figure class. Examples (the following are all examples in the class)

self.fig = plt.figure()
self.axes = self.fig.add_subplot(111)  # Create a subgraph
self.fig.clear() # Clear the subplot first
self.axes = self.fig.add_subplot(111) # Create a subplot


Read More: