Python writes figure to PDF

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.