Reputation: 191
I've been wondering this forever: How can I set graphs in Matplotlib to share axes when I use the plt.subplot(221) (for example) command? Rather than saying:
fig, axes = plt.suplots(2,2,sharex=True, sharey=True)
I would like to say:
plt.subplot(221, sharex=True, sharey=True)
So that I don't have to deal with this annoying array that plt.subplots returns, but obviously this doesn't work.
Upvotes: 0
Views: 255
Reputation: 31339
You can use tuple unpacking to avoid creating the axes
array:
fig, ((ax1, ax2), (ax3, ax4)) = plt.suplots(2, 2, sharex=True, sharey=True)
Afterwards you can plot as usual.
e.g. ax2.plot(...)
will then plot to the top right subplot.
Upvotes: 1