How to draw 1D histogram in a TImage?

Hi

I’m trying to draw a TH1F histogram in a TImage object using the SetImage() method (similar to the tutorial hist2image.C).

However I can’t seem to understand how to do it. The documentation in this area of ROOT is very sparse. I managed to get the 1D representation of the data, with a colourpallet discribing the bins, but I would like to actually plot the data as a histogram/graph with a y-axis.

Also, are there more descriptions or examples of how to use TImage and associated classes? Even the class reference doesn’t have much notes for use.

Thanks

p.s. I’m using root 5.22

Here is an example. Is that what you want ?

{
   TCanvas *c1 = new TCanvas("c1","",200,10,700,500);
   c1->SetGrid();

   const Int_t n = 10;
   Double_t x[n], y[n];
   for (Int_t i=0;i<n;i++) {
     x[i] = i*0.1;
     y[i] = 10*sin(x[i]+0.2);
   }
   y[5]= -10;
   gr = new TGraph(n,x,y);
   gr->Draw("AC");     
   c1->Print("c1.gif");

   TCanvas *c2 = new TCanvas("c2","",200,560,700,500);
   c2->Draw();
   TImage *i1 = TImage::Open("c1.gif");
   i1->Draw();
}

Thanks couet.

Yes I think that could work, but I’m concerned about performance. Can the Print() to file, then Open() steps be skipped?

You see I’m trying to embed/merge data into a live camera feed (probably at 10fps), so a more immediate method would be best.

In fact, browsing the forum, it seems you should use “FromPad”, like is the following example I found:

void imag() 
{ 
   TCanvas *c1 = new TCanvas("c1","c1",800,600);; 
   TH1F *h = new TH1F("gaus", "gaus", 100, -5, 5); 
   h->FillRandom("gaus", 10000); 
   h->Draw(); 

   c1->Update(); 
   TCanvas *c2 = new TCanvas("c2","c1 rotated",600,800);; 
   c2->Divide(1,2); 
   TImage *img = TImage::Create(); 

   img->FromPad(c1);

   c2->cd(1); 
   img->Flip(90); 
   img->Draw("x"); 
   c2->Update(); 
   c2->cd(2); 
   img->Flip(90); 
   img->Draw("x"); 
   c2->Print("c2.gif"); 
} 

FromPad()!

I should have used the search on the Forum. I used google on the site, and the search on the ROOT homepage. Both failed to show that post.

Anyway thanks for that, I will give it a try.

p.s. That method and the other TImage class methods are not documented. It’s all trial and error to discover what these methods do! Someone should do some quick documentation of these classes (please).

In fact TImage is an abstract class and the concrete implementation is the class TASImage. You will find the documentation in that class. But I agree with you that from TImage itself it is not clear. I will make it more clear and also revisit TASImage help.

I have made more clear from the TImage doc that all details are in fact in TASImage.

Thank you! That’s very helpful :slight_smile: