Is it possible to create a .png file without screen output?

Hi, I have a rather easy question but I couldn’t find any answer yet. I am new to ROOT and I’m developing a data analysis software which produces a lot of graphs and plots. I am using Python+ROOT for the purpose in this way: (I call ROOT from Python…)

C=ROOT.TCanvas(…)
P=ROOT.TGraph(…
P.Draw(“L”)
C.Print(filename.png)
C.Close()

It works great but unfortunately it produces a lot of screen output, which is not necessary and very slow (especially if I work remotely through SSH). Is it possible to do the same without producing any screen output and “silently” saving the canvas?

Thank you very much
Emanuele

You can start ROOT in batch mode. (with no screen output at all)

root.cern.ch/cgi-bin/print_hit_b … #first_hit

[quote]New printing facilities in batch via TASImage
TASImage is an interface to image processing library using libAfterImage. It allows reading and writing of images in different formats, several image manipulations (scaling, tiling, merging, etc.) and displaying in pads. The size of the image on the screen does not depend on the original size of the image but on the size of the pad. Therefore it is very easy to resize the image on the screen by resizing the pad.
Besides reading an image from a file an image can be defined by a two dimensional array of values. A palette defines the color of each value.

The image can be zoomed by defining a rectangle with the mouse. The color palette can be modified with a GUI, just select StartPaletteEditor() from the context menu.

The new class TImageDump using TASImage and derived from TVirtualPS allows to save canvas in GIF, JPEG etc, image formats in batch mode. Before this clas was intriduced it was not possible to generate bitmap files (in particular GIFfiles) in batch, such files were generated from a TCanvas. Now the method TPad::Print or TPad::SavesAs can be used in macro running in batch (root -b) to generated bitmap files (gif, jpeg, png, xpm, tiff). Example:

 $ root -b
 root [0] .x hsimple.C
 root [1] c1->Print("c1.gif");

The full description of TPad::Print options is [/quote]

With Qt-layer on you can use TEmbeddedPad class too: root.bnl.gov/QtRoot/htmldoc/TEmb … escription However I do not know whether you can use it from the Python. I never tried that.

Hi Valery, thank you for the prompt reply!
Unfortunately the solution you propose doesn’t seem to work from Python (maybe I’m wrong, but I couldn’t get it to work) but I was hoping that there was a simpler way to go: for instance:
I have been using matplotlib+pylab under python, which is a Matlab-like interface to python, very intuitive but also very slow if compared to ROOT. I have to say that I was really stunned on how great ROOT is. However, in matplotlib you do something like this:

figure() #creates a figure
plot(…) #plots the things you want
show() #IF you want ANY screen output. if not just drop this line
savefig(…) #saves the figure

if there was a similar way with ROOT that would be really great

anyway thanks again for the tips and best regards!
Emanuele

To generate a png file, simply do
canvas.Print(“canvas.png”)

If you have an old version, moce to version 5.11/06

Rene

Hi,

for python, you need to tell the interpreter that the CLI argument is meant for your code downstream, not for the interpreter itself. Thus, do:[code]$ python - -b

import ROOT
ROOT.gROOT.IsBatch()
1
[/code]
Note the extra ‘-’ which tells python that its arguments have ended, and that everything that follows is meant for modules that will be loaded. If you have a script, the ‘-’ isn’t needed, as the location of ‘-b’ suffices:$ python myscript.py -b
HTH,
Wim