I want to plot 5 figures, in a subplot grid of 2 x 3 figures.
How to do this?
There would be an extra empty grid for the 6th subplot. I want to avoid that.
I want to plot 5 figures, in a subplot grid of 2 x 3 figures.
How to do this?
There would be an extra empty grid for the 6th subplot. I want to avoid that.
Welcome to SO! This question has been answered before here but I'll offer an alternate solution using gridspec
Here's 5 axes with a gap:
import matplotlib.pyplot as plt
import matplotlib as mpl
fig = plt.figure()
spec = mpl.gridspec.GridSpec(ncols=3, nrows=2)
ax1 = fig.add_subplot(spec[0,0])
ax2 = fig.add_subplot(spec[0,1])
ax3 = fig.add_subplot(spec[0,2])
ax4 = fig.add_subplot(spec[1,0])
ax5 = fig.add_subplot(spec[1,1])
Here's a more balanced 5 plot layout:
fig = plt.figure()
spec = mpl.gridspec.GridSpec(ncols=6, nrows=2) # 6 columns evenly divides both 2 & 3
ax1 = fig.add_subplot(spec[0,0:2]) # row 0 with axes spanning 2 cols on evens
ax2 = fig.add_subplot(spec[0,2:4])
ax3 = fig.add_subplot(spec[0,4:])
ax4 = fig.add_subplot(spec[1,1:3]) # row 0 with axes spanning 2 cols on odds
ax5 = fig.add_subplot(spec[1,3:5])