I am trying to make a grid of subplots where one axis spans two grid locations. I can achieve this easily with plt.subplots
, gridspec_kw
, and plt.subplot2grid
:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(2,3,sharex=True, sharey=True, gridspec_kw={'width_ratios':[1,1,0.8]})
axi = plt.subplot2grid((2,3),(0,2),rowspan=2)
plt.show()
However, I want the spanning axes on the right to be narrower. When I change width_ratios
to [1,1,0.5]
, I get this:
What happened to the other axes? Based on this answer, I can achieve what I want using GridSpec
directly rather than using the convenience wrappers:
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
fig = plt.figure()
gs = GridSpec(nrows=2, ncols=3, width_ratios=[1,1,0.5])
ax0 = plt.subplot(gs[0,0])
ax1 = plt.subplot(gs[0,1],sharey=ax0)
ax2 = plt.subplot(gs[1,0],sharex=ax0)
ax3 = plt.subplot(gs[1,1],sharex=ax1,sharey=ax2)
ax4 = plt.subplot(gs[:,2])
[plt.setp(z.get_yticklabels(),visible=False) for z in [ax1,ax3]]
[plt.setp(z.get_xticklabels(),visible=False) for z in [ax0,ax1]]
plt.show()
While this works, it is tedious to have to set everything manually, especially when I can get so close with just two lines of code. Does anybody have thoughts on how to make this work using subplots
/subplot2grid
or am I stuck doing it the long way? Is this worthy of an issue report on GitHub?