There are times when you need to check the correctness of Python into a diagram, you need to lose the figure to see, but the citrus is not very convenient, so the internet to find a better way is to print all the figures to PDF files, and then check more convenient. See this method on the Matplotlib website, the simple summary is as follows:
Need to use is
Matplotlib.backends.backend_pdf. Pdfpages
Here is a brief procedure
Import Pdfpages
As Plt
PDF = pdfpages (' cut_figure.pdf ') #先创建一个pdf文件
Plt.figure
...
...
Pdf.savefig () #将图片保存在pdf文件中
Plt.close ()
Pdf.close () #这句必须有, otherwise the program end PDF file cannot be opened
The above is a single picture saved to a PDF, if you have more than one picture, you can write multiple such steps
So what if there is a loop in the program that has a result graph for Each loop? That just needs to put Pdf.close () outside the entire loop.
Python writes figure to PDF