Make matplotlib subplot width match the figure above that has a broader X axis

Viewed 39

I am trying to display some 2D data as a 1D plot versus a model, as well as as a 2D plot. However, the model x axis is broader than the data x axis, so the panel below does not match in width.

I added an example figure with some random data below. The lower right panel is the one that is not working. I would like it to have the size of the red square, or be the full width with some padding maybe. Can this be done without changing the array? I tried setting the aspect to 'auto', but then the full thing becomes 20-80 wide and still does not match.

Working code example given below.

enter image description here

Here is the same figure with real data in it, as I think that that might illustrate the problem better. I basically want the black bands to align with the dips in the data. enter image description here

wfull = np.arange(100)
wpart = np.linspace(20,80,60)

ifull = np.sin(wfull/10)
ipart = np.sin(wpart/10)+np.random.random(60)/10

fig= plt.figure(figsize=(11.7,8.3))
gs=GridSpec(4,2) # 3 rows, 3 columns

ax1=fig.add_subplot(gs[0,0])
ax1 = plt.imshow(np.random.random([200,500]))
ax2=fig.add_subplot(gs[1,0])
ax2 = plt.imshow(np.random.random([200,500]))
ax2=fig.add_subplot(gs[2,0])
ax3 = plt.imshow(np.random.random([200,500]))
ax2=fig.add_subplot(gs[3,0])
ax4 = plt.imshow(np.random.random([200,500]))

ax5=fig.add_subplot(gs[2:,1])
ax5.imshow(np.random.random([60,100]), extent=[wfull[0],wfull[-1], -1,1], cmap='gray', vmax=1, vmin=0)#, aspect='auto')
ax5.set_xlabel(r'wavelength [m$\mathrm{\AA}$]')
ax5.set_ylabel(r'$\mu$')


ax6=fig.add_subplot(gs[:2,1])
ax6.plot(wfull, ifull, label='N&L')
ax6.plot(wpart, ipart, label='N&L')
ax6.set_ylabel(r'I/$I_0$')
ax6.legend()
0 Answers
Related