gnuplot epslatex functionality in matplotlib
Asked Answered
U

1

11

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?

Unalterable answered 1/6, 2011 at 8:24 Comment(2)
Well, I cross-posted this question to the Matplotlib mailing lists here, so I am waiting for response there too.Unalterable
I came to the conclusion that the good LaTeX-rendered text in LaTeX figures could only be achieved with TikZ/PGFplots -- which have many other disadvantages for figure creation. Psfrag has the problem that, while LaTeX renders the text, the size of the substituted text isn't known by the program generating the figure, so text is often improperly positioned.Sontag
U
5

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.

Unalterable answered 2/6, 2011 at 9:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.