开发者

gnuplot epslatex functionality in matplotlib

开发者 https://www.devze.com 2023-03-09 13:03 出处:网络
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:

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开发者_如何学JAVA had with gnuplot.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号