matplotlib subplot without gaps but the last one

自古美人都是妖i 提交于 2019-12-02 11:19:49
Diziet Asahi

An alternative to the answer by @GlobalTraveler is to chain two Gridspec definitions. See here for more information about the possibilities offered by GridSpec.

outer_gs = matplotlib.gridspec.GridSpec(2,1, height_ratios=[3,1], hspace=0.2)
inner_gs = matplotlib.gridspec.GridSpecFromSubplotSpec(3,1, subplot_spec=gs0[0], hspace=0)

fig = plt.figure()
ax1 = fig.add_subplot(inner_gs[0])
ax2 = fig.add_subplot(inner_gs[1])
ax3 = fig.add_subplot(inner_gs[2])
ax4 = fig.add_subplot(outer_gs[1])

One you could solve this is by inserting another subplot and them playing around with the height ratios. Let's start with the results;

Which is achieved by:

import matplotlib.pyplot as plt


gs = dict(\
         height_ratios = [1, 1, 1, .2, 1]
         )

fig, ax = plt.subplots(5, 1, gridspec_kw = gs)
fig.subplots_adjust(hspace = 0)
ax[3].axis('off')
fig.show()

You need to play around with the ratios to achieve the desired results, but the approach could be used to achieve what you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!