Hi Eric,
I think I’ve isolated the problem. In my figure I have been including colorbars for each plot. In my simple example, which I include below, label_outer works without the colorbars but not with them.
Regarding using sharey, I am using the same y-axis in each row, but they differ between rows. If I use sharey, things get all messed up - the smaller images are shrunken and only take up part of the figure. In the end I was able to turn off the tick labelling by doing things like:
for label in ax.get_yticklabels(which=‘both’):
label.set_visible(False)
I think this may have to do with the attributes of axs getting overwritten or something. If I print
axs[1,1].get_subplotspec().colspan.start
in the case with colorbars I get 0, whereas if I do it without colorbars, I get 1 as I should. Same applies to other axes and to rows.
Here’s the minimal example:
import numpy as np
import matplotlib.pyplot as plt
fig,axs = plt.subplots(2,2)
img0 = np.random.random((10,10))
img1 = np.random.random((10,10))
img2 = np.random.random((10,10))
img3 = np.random.random((10,10))
cax0 = axs[0,0].imshow(img0,extent=[0.,10.,0.,10.])
fig.colorbar(cax0,ax=axs[0,0],pad=0.01)
cax1 = axs[0,1].imshow(img1,extent=[0.,10.,0.,10.])
fig.colorbar(cax1,ax=axs[0,1],pad=0.01)
cax2 = axs[1,0].imshow(img2,extent=[0.,10.,0.,10.])
fig.colorbar(cax2,ax=axs[1,0],pad=0.01)
cax3 = axs[1,1].imshow(img3,extent=[0.,10.,0.,10.])
fig.colorbar(cax3,ax=axs[1,1],pad=0.01)
for ax in axs.flat:
ax.label_outer()
plt.show()
···
Jonathan D. Slavin
Astrophysicist - High Energy Astrophysics Division
Center for Astrophysics | Harvard & Smithsonian
Office: (617) 496-7981 | Cell: (781) 363-0035
60 Garden Street | MS 83 | Cambridge, MA 02138