python - Improve subplot size/spacing with many subplots in matplotlib -


very similar this question difference figure can large needs be.

i need generate whole bunch of vertically-stacked plots in matplotlib. result saved using figsave , viewed on webpage, don't care how tall final image long subplots spaced don't overlap.

no matter how big allow figure be, subplots seem overlap.

my code looks like

import matplotlib.pyplot plt import my_other_module  titles, x_lists, y_lists = my_other_module.get_data()  fig = plt.figure(figsize=(10,60)) i, y_list in enumerate(y_lists):     plt.subplot(len(titles), 1, i)     plt.xlabel("some x label")     plt.ylabel("some y label")     plt.title(titles[i])     plt.plot(x_lists[i],y_list) fig.savefig('out.png', dpi=100) 

try using plt.tight_layout

as quick example:

import matplotlib.pyplot plt  fig, axes = plt.subplots(nrows=4, ncols=4) fig.tight_layout() # or equivalently,  "plt.tight_layout()"  plt.show() 

without tight layout

enter image description here


with tight layout enter image description here


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -