当布局='constrained'时,有没有办法调整子图之间的空间?

MEH*_*TAY 8 python matplotlib subplot

我试图消除两个特定轴之间的垂直空间;然而plt.figure(layout='constrained')阻止matplotlib.pyplot.subplots_adjust(hspace=0)

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()
Run Code Online (Sandbox Code Playgroud)
  • 一般情况下都有次要情节;但ax5和ax6之间有差距

一般情况下都有次要情节; 但ax5和ax6之间有差距

没有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()
Run Code Online (Sandbox Code Playgroud)
  • 所需的 ax5 和 ax6

所需的 ax5 和 ax6

使用subplots_adjust(hspace=0)withlayout='constrained'不起作用,它会产生警告UserWarning:该图使用了与 subplots_adjust 和/或ight_layout 不兼容的布局引擎;不调用 subplots_adjust。