def write_pdf(fname, figures):
    doc = PdfPages(fname)
for fig in figures:
    fig.savefig(doc, format='pdf')
doc.close()

def main():
    a = fig_barh(['a', 'b', 'c'], [1, 2, 3], 'Test #1')
b = fig_barh(['x', 'y', 'z'], [5, 3, 1], 'Test #2')
write_pdf('test.pdf', [a, b])
if __name__ == '__main__':
    main()
How to assign a plot to a variable and use the variable as the return value in a Python function