Typesetting of Matlab’s and Python’s Figures in LaTeX
Have you been ever bothered about beautifully typeset papers, books, or lecture notes with ugly non-typeset figures and plots? I am and hence wrote this short article.
It is very easy to export data from Matlab or Python to a text file and to import it into LaTeX using the packages pgfplots and TikZ. It is not just that they typeset figures. Both packages support labeling and references of individual curves. You do not have to change simulations or save a figure once again to change labels, legends, colors of curves, or markers. Just edit the corresponding lines in your LaTeX file. And this approach supports LaTeX and pdfLaTeX.
Following example exports two curves of a plot given as two column vectors Y1 and Y2 vs. column vector X (cf. PgfPlot's manual).
Code Snippet in Matlab
Code Snippet in Python
Note that the vectors are arrays of numpy.
Code Snippet in LaTeX
In your LaTeX file you have to include following code. Note that it shows how curves are labeled and how curves can be referenced in the text (or caption).