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.