Graphing with Cern ROOT

I am trying to create a graph and save it as an image. I have to use ROOT. I created a graph with

TGraph graph = TGraph(xvect, yvect); 

but now I am fixated on how to get this as a png (or other image format). I use a Linux machine if that matters. Also, if anyone knows a link to the documentation describing the method of writing the graph to an image file, I could figure it out myself from there, but I have not been able to find it in the documentation so far.

+4
source share
3 answers
 TCanvas*c1 = new TCanvas(); graph->Draw(); c1->Print("name.png"); 

Will work in cint shell. Compiling the code may require some tweaking.

You will find all of these key materials, exhaustively covered online tutorials and HowTos . Also see the documentation as a whole.

+3
source
 TCanvas*cvs = new TCanvas(); graph->Draw(); cvs->SaveAs("name.png"); 

SaveAs helped me keep the schedule at the root. As an additional note, online documentation is very useful, as dmckee said. class list

0
source

The full macro will be:

 TCanvas *c1 = new TCanvas(); const Int_t n = 10; Double_t xvect[n]; Double_t yvect[n]; .... initialize xvect and y vect TGraph graph = TGraph(n, xvect, yvect); graph->Draw("al"); // draw the graph as a line (see the ROOT wen site for more option) c1->SaveAs("c1.png"); // many other formats are available (PS, PDF, JPEG etc...) 
0
source

All Articles