Setting active subplot using axes object in matplotlib?

You can use plt.axes to set the current active axes. From the documentation: "axes(h) where h is an axes instance makes h the current axis."

import matplotlib.pyplot as plt

x = [0 ,1, 2]
y = [10 ,20, 30]

fig, axs = plt.subplots(2,1)

plt.axes(axs[0])
plt.plot(x,y)
plt.axes(axs[1])
plt.plot(y,x)
plt.show()

The method plt.axes is deprecated for this use. Use plt.sca instead. Following the example above:

import matplotlib.pyplot as plt

x = [0 ,1, 2]
y = [10 ,20, 30]

fig, axs = plt.subplots(2,1)

plt.sca(axs[0])
plt.plot(x,y)
plt.sca(axs[1])
plt.plot(y,x)
plt.show()