I'm trying to remove the vertical space between two specific axes; however plt.figure(layout='constrained')
prevents matplotlib.pyplot.subplots_adjust(hspace=0)
.
With layout='constrained'
import matplotlib.pyplot as pltfig = plt.figure(figsize=(10, 8),layout='constrained')# fig = plt.figure(figsize=(10, 8))subfigs = fig.subfigures(2, 1)axsUp = subfigs[0].subplots(1, 3)subfigsnest = subfigs[1].subfigures(1, 2, width_ratios=[1, 2])ax = subfigsnest[0].subplots(1)axsnest = subfigsnest[1].subplots(2, 1, sharex=True)subfigsnest[1].subplots_adjust(hspace=0)plt.show()
- Generally subplots are in place; but there is a gap between ax5 & ax6
Without layout='constrained'
import matplotlib.pyplot as plt# fig = plt.figure(figsize=(10, 8),layout='constrained')fig = plt.figure(figsize=(10, 8))subfigs = fig.subfigures(2, 1)axsUp = subfigs[0].subplots(1, 3)subfigsnest = subfigs[1].subfigures(1, 2, width_ratios=[1, 2])ax = subfigsnest[0].subplots(1)axsnest = subfigsnest[1].subplots(2, 1, sharex=True)subfigsnest[1].subplots_adjust(hspace=0)plt.show()
- Desired ax5 & ax6
Using subplots_adjust(hspace=0)
with layout='constrained'
doesn't work and it produces the warning UserWarning: This figure was using a layout engine that is incompatible with subplots_adjust and/or tight_layout; not calling subplots_adjust..