简体   繁体   中英

How to adjust subplots borders in matplotlib automatically?

When plotting multiple plots using plt.subplots , most of the time the spacing between subplots is not ideal so the the xtick labels of the top plot would overlap with the title of the bottom plots. There is a way to fix this manually by calling say plt.subplots_adjust(hspace=0.5) and changing the parameters interactively to obtain a decent looking plot. Is there a way to calculate the subplot_adjust parameter automatically? Meaning finding the minimum hspace and wspace so that there is not overlap between texts of the plots.

I'm pretty certain that the closest your going to find to an inbuilt calculation method is:

 plt.tight_layout() or figure.Figure.tight_layout() #if you are using the object version of the code

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