简体   繁体   中英

Adjust the distance only between two subplots in matplotlib

I have 3 subplots (3 rows and 1 column). We can use fig.subplots_adjust(hspace=0.2) to adjust the distance between the subplots. this will change the distance between subplots for all case. How can I have different distance between plot 1 (311) & plot 2 (312), and plot 2 (312) & plot 3 (313)?

Good question. Try this:

from mpl_toolkits.axes_grid1 import make_axes_locatable 

ax1 = plt.subplot2grid((1,1), (0,0))
divider = make_axes_locatable(ax1) 
ax2 = divider.append_axes("bottom", size="100%", pad=0.5)
ax3 = divider.append_axes("bottom", size="100%", pad=1)

Then you would get:

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM