[Tex/LaTex] What are the benefits of PGFPlots/TikZ compared to importing PDF

graphicspgfplotsplottikz-pgf

What are the benefits of using tools like pgfplots or tikz directly in LaTeX compared to importing PDF/PGF generated by say matplotlib?

This answer believed that the main reason is to match the plots with the rest of the document. It also mentioned that no other plotting packages from R or python can generate graphs that have the same high image quality as those generated by pgfplots in LaTeX directly, but no examples or reasons were given. Is there evidence to back up this claim?

Another related question is that, is there any reason for exporting a plot to PGF instead of PDF? This comment said that the reason is PGF will generate the whole graph in LaTeX while importing to PDF even with usetex will only use LaTeX for the text part of the graph. But if the main reason for plotting in LaTeX is that we can match the plots with the rest of the text document, usetex exactly does that.

My current adopted approach to producing PDF documents with graphs is (i) generate graphs using tools like matplotlib or other plotting packages in a scientific programming language so that I can do computations before plotting or plot repetitive graphs; (ii) export to PDF files and use usetex if I want to match the font with my document; (iii) import the PDF files using \includegraphics and make final adjustments.

This seems to work out just fine and I didn't notice any image quality issues or graph not matching with the rest of the document.

So are there any other reasons to use native plotting utilities like pgfplots in LaTeX that I overlooked?

Best Answer

Welcome to TeX.SE! I think that, as long as you feel comfortable with the way you are producing and embedding the plots, and are happy with the result, this should be the way to go. I personally use TikZ and pgfplots for sufficiently simple plots (after I switched there from pstricks). My main motivation are points that are not in your list:

  1. I do not have to open several files and adjust things.
  2. If I include the graph in a beamer presentation, it automatically comes with the right font as the ambient document. If I understand you correctly, if I were to use the method you suggest I would have to produce a separate pdf for the beamer presentation.
  3. I also use some macros. Even though I do not use many of them, I find it sometimes convenient to define some symbols via a macro. I can use this macro also in my plots and figures.
  4. Even though this is not a major issue, when working on something together with others on a file just works. I do not have to worry that my collaborators may not have downloaded another plot from the repository. Rather, once they have the file, they have all they need to compile the document. Likewise, my collaborators can also add figures and plots in the same way without having to worry about these issues.

Having said this, let me also mention that there are sufficiently complicated plots which I do not do with pgfplots or TikZ. After all, LaTeX is not a computer algebra system.

Related Question