Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnuplot epslatex functionality in matplotlib

I am used to plot data with gnuplot, so I can easily put the figures in a LaTeX document, using the epslatex terminal. For example:

file = "data.dat"

set terminal epslatex
set output "figure1.tex"

plot file

This way, two files are generated: one .eps file, which contains the graphics, and one .tex file, which contains the text. The great advantage of this is that text is rendered by LaTeX, so the tics, labels, etc. have the same font as the rest of the document.

Now I am starting with matplotlib, which has a much nicer API, is more scriptable and, well, is Python. But, even though I can make matplotlib render the text with LaTeX, it gets embedded into the image and I cannot achieve the same advantages I had with gnuplot.

Is there any way I can emulate the epslatex terminal in matplotlib?

like image 600
astrojuanlu Avatar asked Jun 01 '11 08:06

astrojuanlu


1 Answers

Update: matplotlib 1.2 introduced a new PGF/TikZ backend, and I have successfully used it for the exact purpose stated in this question: make LaTeX / XeTeX render the text of the plot. In the documentation there are some nice examples of plotting using the PGF backend, including custom preambles, custom fonts and full unicode math support.

like image 121
astrojuanlu Avatar answered Nov 20 '22 00:11

astrojuanlu