Plot mode similar to gnuplot's epslatex

Hi Rooters,

is it possible, to plot a histogram similar to gnuplot’s “epslatex” terminal? What that does, is to create an “.eps” file together with a “.tex” file, where the tex file contains all text, like legends, and the eps file contains the plot itself. This makes a nice plot with text, which is easily adjustable, fully latex-capable, and identical in appearance with the rest of your document!

If you want to try it yourself, start “gnuplot” and type:

gnuplot> set terminal epslatex color
gnuplot> set output "filename.eps"
gnuplot> plot [0:2*pi][-0.6:0.6] 0.5*sin(x) title "$\\frac{1}{2} \\sin(x)$"
gnuplot> quit

This should have created the files “filename.eps” and “filename.tex”, which you can now add to your latex document with


where the scalebox can be used to adjust the size.

Is it possible to do this with ROOT, and if not, could it be considered?


Yes, draw your text using TLatex on TCanvas on which your plot is and save all as eps.

Thanks for your reply, couet.

I meant something else: Of course it is possible to create an eps file containing latex text, but the special thing about the “epslatex” mode I was talking about, is the separation of eps (plot) and latex (text). This has many advantages for me, of which the two most important ones are:

  • I can easily change the text later on (without redoing the whole plot)
  • The text in the plot appears in native latex fonts, not ROOT’s fonts. This gives a nice consistent appearance of your document.

As far as I can see, this is not possible with “saving as eps”.

when you have a canvas, you can save it in various formats, in particular
The canvas.C contains all the instructions (including the Latex expressions). You can modify this script and execute it again to produce another canvas.eps file.


Hi Rene,

Which still doesn’t give control over e.g. fonts because latex processing is still done by TLatex not pdflatex or whatever.

I completely agree that this would be a really nice enhancement.



thank you for your advise, but this only helps for the first point (and is still not as convenient, but that’s only a minor issue).

Having the axis labels, titles, legend etc. appear in my latex document’s fonts would give a much more pleasant appearance, and I have gotten quite used to it. :slight_smile:

Thanks for your consideration,

I think you can simply generate an ASCII file containing the piece of text you would like to include later in the latex document. A simple macro doing the output would do the job.

It’s not that simple. The function would have to care about proper positioning of the text with respect to the eps-file. I don’t want to do that myself in Latex. And it’s a bit of work, to do this in a macro properly, that’s why I was wondering, whether it is of general enough interest, to include it as print mode in ROOT. And as Axel replied, there seems to be.
Have you had a look at the example I suggested? Maybe it convinces you better than all talking?

Yes I saw the output, and that sort of things is not a 5 minutes work.
I was trying to suggest some easy solution. Like:

% filename.tex
Here put you text directly... may be in a Latex Caption ...

I found another use case, where such a feature would be really nice to have: If you want to include citations (for example through bibtex) within your legend entries. As far as I know, this is not possible at all with ROOT histograms so far.


In fact what you are requesting is

canvas.Print("canvas.tex"); that will generate a “canvas.tex” file with all text and image scaling instructions and an associated “canvas.eps” file with the dumb graphics.

Olivier, one more thing for your todo list.


[quote=“brun”]In fact what you are requesting is

that will generate a “canvas.tex” file with all text and image scaling instructions and an associated “canvas.eps” file with the dumb graphics.

Olivier, one more thing for your todo list.
Yes, this is exactly what I had in mind. It would be great to have this print mode.

Thanks for the consideration,

So that means all the text (axis labels, axis title, legend etc …) clearly written in ASCII in a Latex file and all the rest (line etc) in EPS ? and you want the EPS aligned on the text ?

If that is really what you want that is not easy at all to do, even impossible I guess, because it depends on the context of the latex document in which it will be included and because Latex is a text processing program and you cannot place items at pixel positions like in EPS. I guess with this “2 files approach” you can may be generate a caption corresponding to the histogram title but for all other texts (axis label in particular) that will be a nightmare and the result will never be perfect. Also what do you do when you have a divided pad ? you generate one EPS file per sub-pad and then try to align them on a grid in LaTex ?

In the old days, in PAW, was implemented a LaTex driver which generated one single LaTex file for that purpose. The author of that code had implemented a complete driver to generate ALL graphics in latex just because it is impossible to align all text on the EPS file(s). Even the lines, polygons etc were generated in LaTex. So the text looked good but the pure graphics was far to have the EPS quality and some graphics was not rendered at all (hatches etc …).

couet: Yes, this is exactly what I was trying to describe. It must be possible, because gnuplot is doing it. Of course you have to assume that in the document the eps figure does not get included scaled in respect to the latex text. But this can easily be avoided by scaling them both together with a \scalebox{} around them.

By the way: It is not only the text that is included in the latex file, but also the \includegraphics{file.eps} command. That way you then input the plot into your document: \input{file.tex} instead of the \includegraphics{file.eps} that you would usually do.

Please tell me if you would like me to attach the .eps and .tex for an example plot.

yes please put some attachement produced by gnuplot.

Ok, here it goes. Should compile with “latex document.tex”.
epslatex.tar.gz (26.5 KB)

Ok I see the result. Yes all the text is rendered wih latex. I confirm it is not a trivial task to implement that. I can only put it on our wish list for the time being.

I realise this is a very old post, but I think it is still relevant and would be a fantastic additions. I use the epslatex output from gnuplot often, and I feel a little let down when I can’t do make these simple outputs with root. Even though this isn’t such a simple addition, surely it would be worth it? Is there any update?


Nothing new on that.

I use a workaround for plotting with gnuplot to eps inside a ROOT script.

I create a text file with the parameter plots in gnuplot, called "mygraph.plt"
It contains for example:
set terminal epslatex color (or alternatively: set terminal postscript enhanced color)
set output "filename.eps"
plot x, "data.txt"

I assume every file is in the same folder as the script.

Then, in a ROOT script, I tell ROOT to execute gnuplot with this file, with a curious sentence:
if(system(“gnuplot mygraph.plt”))
cout << “Correctly plotted with gnuplot\n”;
cout << “error\n”;

Optionally, the same if you want to convert from epstopdf (this time without verbosity-error messages):
if (system(“epstopdf Porcentajes_LYSO_Ecut.eps”)){}

Other alternatives: create a string s=“gnuplot …” with the sentence, and type gSystem->Exec(s);

This way, you avoid creating the plot in gnuplot manually after you have obtained some data results in ROOT.