L-shaped Gridspec using matplotlib gs.update

1.2k views Asked by At

This one is a quick and easy one for the matplotlib community. I was looking to plot an L-shaped gridspec layout, which I have done:

enter image description here

Ignoring a few layout issues I have for the moment, what I have is that the x-axis in the gs[0] plot (top left) shares the x-axis with the gs[2] plot (bottom left) and the gs[2] shares its y axis with the gs[3] plot. Now, what I was hoping to do was update the w-space and h-space to be tighter. So that the axes are almost touching, so perhaps wspace=0.02, hspace=0.02 or something similar.

I was also hoping that the bottom right hand plot was to be longer in the horizontal orientation, keeping the two left hand plots square in shape. Or as close to square as possible. If someone could run through all of the parameters I would be very appreciative. I can tinker then in my own time.

1

There are 1 answers

0
GCien On

To change the spacings of the plot with grid spec:

 gs = gridspec.GridSpec(2, 2,width_ratios=[1,1.5],height_ratios=[1,1])

This changes the relative size of plot gs[0] and gs[2] to gs1 and gs[3], whereas something like:

gs = gridspec.GridSpec(2, 2,width_ratios=[1,1],height_ratios=[1,2])

will change the relative sizes of plot gs[0] and gs1 to gs[2] and gs[3].

The following will tighten up the plots:

gs.update(hspace=0.01, wspace=0.01)

This gave me the following plot:

enter image description here

I also used the following to remove the axis labels where needed:

nullfmt = plt.NullFormatter()

ax.yaxis.set_major_formatter(nullfmt)
ax.xaxis.set_major_formatter(nullfmt)