Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I’m looking for a professional and efficient way to create scientific graphics. There are basically two types of graphics I want to create (and maybe not a joint approach works for both):

Plots of functions and data, and free body-type diagrams.

Until now I’ve been using Mathematica with MathPSfrag, but this seems too bulky now. I know about gnuplot, TikZ, and Inkscape, although I haven’t used them extensively. So I come here looking for suggestions.

Some requirements:

  • Pdf-output to a separate file, since some journals want it that way.
  • Have the typesetting of text and math done by a TeX-engine to get a coherent look between main text and text in figures (probably by adding a LaTeX- or XeTeX- header).
  • Cross-platform (Windows/Linux).

Also, feel free to post your workflow for creating graphics.

share|improve this question
Have you looked into PGF plots? –  DJP Oct 13 '11 at 13:57
Try using the R statistics package (R-Project) available for many Linux distros, Windows and Mac. You can operate it with scripts which allows you to automate many graph making processes and seems to be a bit more intuitive than Gnuplot. It outputs graphs directly to PDF. Just realized, however, that it may not have the typsetting of text and math done by the TeX-engine but I'm not too experienced with it to know if it can do this. –  LordStryker Oct 13 '11 at 15:10
Can you clarify what you mean by "too bulky"? –  Emre Oct 13 '11 at 22:12
If you like writing C++ macros then Root is a very, very powerful program. It can do just about anything, and can handle huge datasets- it was written by CERN because no existing programs could do what they needed. The downside is you basically have to program all your graph and the documentation is not written for new users. I've used GNUplot before, and have been told it can make publishable documents, but I didn't get them to look nearly good enough for that. On the other hand, I've seen Excel graphs in papers. –  Canageek Oct 18 '11 at 17:52
add comment

5 Answers

up vote 13 down vote accepted

Others have already pointed to pgfplots, which I'd also agree with. It would probably be useful to have some specific pointers on how to use it to best effect. I wrote a TUGBoat article about this a while ago, but I'll try to highlight some key points here.

The first thing to say is that the exact workflow will depend on the journal your are targeting. For example, I need versions of my plots as separate files, so use the standalone class (again, this has already been mentioned). An alternative, particularly if you are looking for speed gains in a a LaTeX document, is to use the 'externalize' library to build the plots just once. The pgfplots manual describes this in detail.

Again, depending on what you are plotting having your data in a simple text format such as .csv or tab-separated makes life easier. This makes it easy to have a simple 'boilerplate' .tex file and slot in your data (name your data file based on your .tex file and you can use \jobname to add the data).

Not directly linked to the choice of data presentation system is the use of colour: it can be very useful, but needs to be done sympathetically. In particular, not all journals are too keen on colour if black-and-while will do.

Some examples from the TUGBoat article (which contains the source):

enter image description here enter image description here enter image description here enter image description here

share|improve this answer
Concerning the scaling: I found convert -density 100 <file.pdf> <file.png> acceptable since I usually have a pdf as input (may need to play with the density argument). This usually appears to be acceptable. –  Christian Feuersänger Oct 13 '11 at 18:02
@YiannisLazarides I assume you mean 'anywhere but TUG'. I've uploaded the source in it's entirity to my blog host: texdev.net/wp-content/uploads/2011/10/pgfplots.zip –  Joseph Wright Oct 13 '11 at 18:43
@JosephWright Thanks for the upload, great article. –  Yiannis Lazarides Oct 13 '11 at 19:14
@ChristianFeuersänger I guess I'm used to the workflow I need to get stuff for print into Word. There, I need to watch the physical size and the resolution, and also need to be able to crop whitespace before resizing. The 'blurriness' I was worried about was the limits on the absolute number of pixels covering a line/text at a small size. It seems that does not show so badly on screen. –  Joseph Wright Oct 13 '11 at 19:17
@Joseph I see your point, thanks for the explanation. –  Christian Feuersänger Oct 13 '11 at 19:34
add comment

For what you are asking the best choice is pgf, tikZ and pgfplots. For free body diagrams see http://www.texample.net/tikz/examples/free-body-diagrams/. Almost every conceivable combination and question involving these can be found on tex.sx and most package authors are active contributors to answers.

share|improve this answer
Thanks for your answer. The example you linked to is beautiful. –  Emerson Oct 18 '11 at 20:07
add comment

I would take a close look at matplotlib. It's a plotting package connected to scipy and numpy. Full tex support for text. There is a threshold to start but once you are into it, you can create very efficient workflows.


Sage is a close relative with a more Mathematica like approach. http://www.sagemath.org/

share|improve this answer
There are some notes about using matplotlib to generate LaTeX figures in the Cookbook. (Getting the right width, choosing fonts, etc.) –  mforbes Oct 18 '11 at 18:58
add comment

As already mentioned, tikz and pgfplots is highly recommended which address the last two points of your question.

To address the first question and be able to generate separate PDFs, I have been using the {standalone} package exactly for this purpose. You create a standalone tex file for each figure and use:


and the main files which include this standalone file will need to have the complete preamble including \usepackage{standalone}. Martin Scharrer, the package author provides a good example here.

share|improve this answer
add comment

R is a good solution for your first question (I don't know about free body diagrams). It offers a full statistical analysis environment, with extensive graphing capabilities.

Mathematical annotations are done using a 'TeX-like' language. For examples, from inside R try:


For graphical possibilities, try


R also provides for saving figures as pdf (and ps, jpeg, png, wmf ...), and is available for Linux, Mac and Windows.

share|improve this answer
90% of my phd thesis graphics were made in R and boy, do they look nice. You can even use a tikzdevice which outputs plots as tikz plots. –  Frank_Zafka Oct 13 '11 at 16:52
Some of the nicest plots I have ever seen were made with R and ggplot2 –  matth Nov 10 '11 at 9:41
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.