Reputation: 161
I am trying to create a number (>100) subplots for later analysis. A grid up to 5x5 seems to work fine, any larger than that and the y-axis begins to get very squashed and the whole thing is unreadable. I have tried various different things, like setting aspect etc, but to no avail.
Here is the output for a 5x50 grid: squashed subplots
and here is my code:
from matplotlib.backends.backend_pdf import PdfPages
pp = PdfPages('./output.pdf')
num_investigate = len(investigate)
ncols = 5
nrows = 50#math.ceil(num_investigate/ncols)
fig, axs = plt.subplots(nrows=nrows, ncols=ncols, sharex=False, figsize=(15,15))
for ax, file in zip(axs.flat, investigate[:(ncols*nrows)]):
try:
df = get_df_from_csv(file)
df['perf'] = df['val'] / df['val'].ix[0] - 1
#ax.set_ylim(bottom=df['perf'].min(), top=df['perf'].max())
ax.set_aspect('auto')
df['perf'].plot(ax=ax, title=file)
except:
pass
plt.tight_layout()
pp.savefig()
pp.close()
I'm at a real loss of how to solve this after much research.
How do I ensure that the each subplot size is constant and the output goes to more than one pdf page?
thanks
Upvotes: 2
Views: 828
Reputation: 339310
PdfPages
saves one matplotlib figure to one page. A second calls to the savefig command will lead to the creation of a second page. Hence, if you want a second page in the output pdf, you need to create a second figure.
E.g. you can produce the first figure with a 5x5 grid and put the first 25 plots in that figure, then save it. Then create the next figure, add the next 25 plots to it and save it again.
There is a multipage_pdf example on the matplotlib page.
Upvotes: 1