Pagebreak inside Subplot? Matplotlib subplot over mulitple pages

后端 未结 2 1521
清歌不尽
清歌不尽 2021-01-23 03:03

I want to create a python programm that is able to plot multiple graphs into one PDF file, however the number of subplots is variable. I did this already with one plot per page.

2条回答
  •  后悔当初
    2021-01-23 03:53

    You can use matplotlib's PdfPages as follows.

    from matplotlib.backends.backend_pdf import PdfPages
    import matplotlib.pyplot as plt 
    import numpy as np
    
    pp = PdfPages('multipage.pdf')
    
    x=np.arange(1,10)
    y=np.arange(1,10)
    
    fig=plt.figure()
    ax1=fig.add_subplot(211)
    # ax1.set_title("cell" + keyInTags)
    # ax1.plot(x, y, color='k')
    # ax.plot(x, y_red, color='k')
    ax2=fig.add_subplot(212)
    
    pp.savefig(fig)
    
    fig2=plt.figure()
    ax1=fig2.add_subplot(321)
    ax1.plot(x, y, color='k')
    ax2=fig2.add_subplot(322)
    ax2.plot(x, y, color='k')
    ax3=fig2.add_subplot(313)
    
    pp.savefig(fig2)
    
    pp.close()
    

    Play with these subplot numbers a little bit, so you would understand how to handle which graph goes where.

提交回复
热议问题