0
votes

I have two questions regarding my figure posted below. I have a figure that contains two types of data as seen below. The top-most subplot (axis handle = ax1) should occupy the full width of the figure (as already done), with the following subplots (left columns has handles ax2:ax6, right column has handles ax7:ax11). I want the ax2:ax11 subplots to all share x/y axes, as shown (I will clean up the labels, etc. later), but I also want there to be space between ax1 and the subplots directly below it so I can see the x-tick labels and x-axis label for ax1 (i.e. have vertical space between ax1 and ax2/ax7). Question 1: Can anyone tell me how this is done?

There is no need to have each subplot's (ax2:ax11) y-axis labeled. Question 2: Can somebody explain how to put one y-axis label on the figure to represent ax2:ax11 (ax1 will have its own y-axis label)?

I create the subplots via:

fig = figure( figsize=(5.5,7.5) )
ax1 = subplot2grid(shape=(6,2),loc=(0,0),rowspan=1,colspan=2)   # dSCD vs SZA
ax2 = subplot2grid(shape=(6,2),loc=(1,0),rowspan=1,colspan=1)   # resid @ SZA==90am
ax3 = subplot2grid(shape=(6,2),loc=(2,0),rowspan=1,colspan=1)   # resid @ SZA==91am
ax4 = subplot2grid(shape=(6,2),loc=(3,0),rowspan=1,colspan=1)   # resid @ SZA==92am
ax5 = subplot2grid(shape=(6,2),loc=(4,0),rowspan=1,colspan=1)   # resid @ SZA==93am
ax6 = subplot2grid(shape=(6,2),loc=(5,0),rowspan=1,colspan=1)   # resid @ SZA==94am

ax7 = subplot2grid(shape=(6,2),loc=(1,1),rowspan=1,colspan=1)   # resid @ SZA==90pm
ax8 = subplot2grid(shape=(6,2),loc=(2,1),rowspan=1,colspan=1)   # resid @ SZA==91pm
ax9 = subplot2grid(shape=(6,2),loc=(3,1),rowspan=1,colspan=1)   # resid @ SZA==92pm
ax10 = subplot2grid(shape=(6,2),loc=(4,1),rowspan=1,colspan=1)  # resid @ SZA==93pm
ax11 = subplot2grid(shape=(6,2),loc=(5,1),rowspan=1,colspan=1)  # resid @ SZA==93pm

fig.subplots_adjust(hspace=0,wspace=0,top=0.95)
ax1.set_xlabel('Text Text Text',fontsize=8)

enter image description here

1

1 Answers

2
votes

You can use GridSpec directly to create two sets of axes, one at the top and one at the bottom and put a space between them. To create a y label for all the axes, use figure text.

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

fig = plt.figure( figsize=(5.5,7.5) )

gs1 = GridSpec(1, 1)
gs1.update(left=0.05, right=0.95, top=0.95, bottom=0.85, wspace=0.05)
ax1 = plt.subplot(gs1[0])
ax1.set_xticks([])
ax1.set_yticks([])

gs2 = GridSpec(5, 2)
gs2.update(top=0.75, hspace=0.05)

for i in gs2:
    ax = plt.subplot(i)
    ax.set_xticks([])
    ax.set_yticks([])

ax1.set_xlabel('Text Text Text',fontsize=8)
fig.text(0.03,0.45,'some label',rotation='vertical')

plt.show()

GridSpec with shared y label