Save canvas in batch mode as gif

I am using ROOT 4.04 in the batch mode to save plots as gif files so that I can later view them on a webpage, but I am having a problem getting the files to save properly. For example, the color mapping of the gif files seems to be messed up. The backgrounds of plots are yellow even though I haven’t specified a background color. However, the canvas background itself remains white.

As a second example of this problem, I am using gStyle->SetPalette(1); so that the 2D Histogram plots are nice and colorful, but the color mapping is all messed up for these gif files as well. I only see shades of blue and yellow in the plots, and I don’t see any reds.

Any suggestions? Thanks!

What is your X-server? that may be a source of the troubles.

On the other hand you can try to apply the “pdf” vector format. It doesn’t rely on any X-server capability at all and good for Web page.


I do not see any problem in batch mode.
Could you precise which version / platform and send a short script showing the problem ?


Thanks for both replies. I am new to ROOT so this will hopefully help me out.

fine: I am not sure what my X-server is. How do I find out what it is?

Bertrand: I also noticed that there is no problem saving gif files when I run ROOT in batch mode from the command line. I am saving plots from a compiled C++ program. The platform I am using is Solaris 9.

Here is a sample script when running in batch mode (fairly standard, I think):

TCanvas *canvas = new TCanvas(1); TH1F *plot = new TH1F("plot","new plot",10,1,10); for(int i=1; i<=10; i++) { plot->SetBinContent(i,i); } plot->Draw(); canvas->Print("file.gif","gif");

I hope this helps. Thanks again!


I don’t see any problem (at least on Windows).
Could you tell me which version of Root you are using ?


I cannot reproduce your problem using version 4.04/02 or newer.
Could you send the shortest possible RUNNING script reproducing your problem?


Actually, I stand corrected. If I run the code that I posted earlier in batch mode then I do not get the correct color output. I am using ROOT version 4.04/02 on a Solaris 9 system. I was mistaken earlier when I said that it would output the correct colors while in batch mode.

Take this code running in batch mode from the command line, for example:

TCanvas *canvas = new TCanvas(1); TF1 *plot = new TF1("plot","sin(x)",0,6); plot->Draw(); canvas->Print("test.gif","gif");

This results in the attached graphic. Notice the yellow background and the very faint sine curve.

Thanks for your help!

When running in batch mode on Solaris9, I can reproduce the problem.
It is a problem internal to the libAfterImage library that seems to link
with an old version of some system libraries (libtiff, libjpeg, etc).
Your test works correctly on Linux and Windows.


Hi Rene,
I guess it is good that it’s not just a problem localized to the computers I use. Do you have any suggestions to fix the problem or is it currently “unfixable”? Thanks for all your help!

As I said, this problem is related with an obsolete version of the libraries libjpeg, libpng, libgif distributed with Solaris and used by libAfterImage.
The fix would consist in testing more uptodate versions of these libraries,
instead of using the Solaris versions.
You should not expect a quick investigation from our side.


Hi Rene,
Thanks for your help! I will see if we can test newer versions of the libraries.

I have one more question about saving the canvas as a gif file. When I am using the Print(“foo.gif”) command in a for loop, I am noticing that the memory usage is going up (using top). Is there a memory leak when using the Print() command? I estimate the memory increase per use of Print() to be ~3 kBytes.

I found someone asking a similar question about this back in 2001. Is this still a problem? Again, I am running ROOT version 4.04/02 on a system running Solaris 9.

Thanks again.