The code below produces a set of plots. However, when exporting the plots using PdfPages only 1 plot is exported for the fig2 plots. Is it possible to export the other plots created - also to the pdf?
for c in df3.columns:
if df3[c].value_counts().count() < 5:
vc = df3[c].value_counts().sort_values()
# Visualization
fig1 = plt.figure();
ax = vc.plot(kind='barh',color=(0.2, 0.4, 0.6, 0.6));
text = c +' (Total)'
ax.set_title(text)
# If
elif df3[c].value_counts().count() / df3.shape[0] < 0.9:
vc = df3[c].value_counts().head().sort_values()
# Visualization
fig2 = plt.figure();
ax = vc.plot(kind='barh',color=(0.2, 0.4, 0.6, 0.6));
text = c +' (Sample)'
ax.set_title(text)
else:
pass
from matplotlib.backends.backend_pdf import PdfPages
pp = PdfPages('foo.pdf')
pp.savefig(fig1)
pp.savefig(fig2)
pp.close()