confused by matplotlib and subplots

Luca please_no at spam.it
Wed Apr 1 17:07:25 EDT 2020


Hello Covid fighters and dodgers,

I'm sort of confused by what I am seeing in a Pandas book.

This works:

fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
ax3.plot(np.random.randn(50).cumsum(), 'k--');

but also this works!

fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
plt.plot(np.random.randn(50).cumsum(), 'k--');

(the second one is actually the example in the book).

Why does it work? Isn't axX referring to one of the subplots and plt to 
the plot as a whole?

Thanks



More information about the Python-list mailing list