Hi Matplotlib Users,
I could not find an answer to this on stackoverflow.
I have two subplots in a figure, nrow=1, ncols=2.
They are of different height. The left is bigger than the right one. Matplotlib aligns them not at the top, but centered.
ax1.set_anchor(‘N’) shows no effect.
Edit: I think this is when I provide in ax1.imshow the aspect explicity.
The idea is here to have on the left the whole image, on the right a zoomed in.
I don’t know what is better: To select the indices or set the zoom via the limits?
The last question is about the height ratio in gridspec. Only height_ratios=[1] works, not 0.5,0.5.
But why can I not set the height ratio for both pictures equal? 0.5., 0.5 because 0.5+0.5=1=nrows?
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
# Data for plotting
Z = np.arange(10000).reshape((100, 100))
Z[:, 50:] = 1
index_array=[40,60,40,50]
figure_size=(10, 7)
fig = plt.figure(figsize=figure_size)
gs = gridspec.GridSpec(nrows=1, ncols=2, height_ratios=[1], width_ratios=[1.2,0.8],wspace=0.5)
fig.subplots_adjust(left=0.05, bottom=0.06, right=0.95, top=0.94, wspace=0.2)
ax0 = fig.add_subplot(gs[0, 0])
im0=ax0.imshow(Z, aspect='auto')
ax1 = fig.add_subplot(gs[0, 1])
im1=ax1.imshow(Z, aspect= (index_array[1]-index_array[0])/(index_array[3]-index_array[2]))
ax1.set_xlim([40,60])
ax1.set_ylim([40,50])
axes=[ax0,ax1]
#common colorbar
plt.colorbar(im0, ax=axes, orientation='vertical')