I want to plot data, in two different subplots. After plotting, I want to go back to the first subplot and plot an additional dataset in it. However, when I do so I get this warning:
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. warnings.warn(message, mplDeprecation, stacklevel=1)
I can reproduce that with a simple piece of code:
import matplotlib.pyplot as plt
import numpy as np
# Generate random data
data = np.random.rand(100)
# Plot in different subplots
plt.figure()
plt.subplot(1, 2, 1)
plt.plot(data)
plt.subplot(1, 2, 2)
plt.plot(data)
plt.subplot(1, 2, 1) # Warning occurs here
plt.plot(data + 1)
Any ideas on how to avoid this warning? I use matplotlib 2.1.0. Looks like the same problem as here