- Be able Include loss-less vector graphics in your Latex document (good).
- Be able to select text inside figures with mouse (awesome).
- Compile your latex document with figures faster (probably).
- Make your files smaller and of higher quality (mostly).
- That's it. The rest is up to you!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\begin{figure} | |
\begin{center} | |
\includegraphics[width=8.3cm]{my_figure.pdf} | |
\caption{This is my figure.} | |
\end{center} | |
\end{figure} |
andersx@awesome:~/my_paper$ pdflatex mypaper.tex
This will also compile much faster than standard latex (using, say, .png-files), since you are now including something that is already in pdf-format.
Last two steps are (1) to save your file as a .pdf-file and (2) autocrop the white borders (loss-less). Step one is accomplished using standard matplotlib/pylab/etc. syntax. The 2nd part is done using a tool called pdfcrop (which is already included in you have latex installed). I prefer to call pdfcrop from within the Python script to avoid having to run more than one command each time I make a new figure.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pylab | |
import numpy | |
import os | |
# Make a simple plot | |
x = numpy.arange(1, 100, 1) | |
y = x**2 | |
pylab.plot(x, y) | |
# Define a filename (remember the .pdf) | |
filename = "my_file.pdf" | |
# Save and convert! | |
pylab.savefig(filename) | |
os.system("pdfcrop %s %s" % (filename, filename)) |
andersx@awesome:~/my_paper$ python my_figure.py
PDFCROP 1.33, 2012/02/01 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 1 page written on `my_file.pdf'.
andersx@awesome:~/my_paper$
Now you have a beautifully formatted pdf-file to include in your latex document.
I might edit this post later with a bit of bling and YOLO/swag just to give it the attractive combination of vitality and glamour it deserves.