Introduction to Matplotlib and simple use of pyplot -- output the image in the eps format

Source: Internet
Author: User

Matplotlib is used at first because it does not need to take a long time to start a graphical interface like Matlab. Second, it can be directly saved as. eps format.
After the image is displayed, there are several buttons in the lower left corner. The last button is save. In the Save dialog box, select. eps format. Another method is to use pyplot in the program. savefig (name, format = "eps"), you can use format to specify the format of eps, Or you can write it in name instead of format, it automatically finds the extension from the name to determine the format.
Although this is done. an image in the eps format, but there is a blank space around it. There are two ways to remove the blank space. One way is to use gsview. On windows, this tool is generally used, another way is to use epstool (http://pages.cs.wisc.edu /~ Ghost/gsview/epstool.htm), the code I use is

print targettp0 = "tp0" + targettp1 = "tp1" + targetplt.savefig(tp0,dpi=160)cmd0 = "epstool -b -t4 --output %s %s" %(tp1,tp0)cmd1 = "epstool -p --output %s %s" %(target,tp1)cmd2 = "rm tp*"os.system(cmd0)os.system(cmd1)os.system(cmd2)

Generally, the output eps files can be used, but sometimes there may be problems. For example, only one part of the image or all the images in the PDF file compiled by latex are blank, the main problem is that the boudningbox in the eps format has a negative value. This is a very troublesome problem and there is no good solution yet. Although epstool can be adjusted, it is possible to recalculate boundingbox, however, there will still be negative values. The temporary solution is to narrow down the image, for example, in the past, it was figsize = (16, 8) and then reduced to figsize = (9, 4.5 ). Currently, the test result is that the width is greater than 10, and the boundingbox will have a negative value, but it is still possible to be bigger than 9, generally 9 is enough, and the font should be reduced accordingly when it is reduced, otherwise, when the default font is used, the current output is too large for the image.
As mentioned above, you can set the boundingbox of fig, but you have not studied it in depth. If you are interested, you can continue to explore it.

So far, the introduction to Matplotlib is over, and new things may be used in the future.

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.