Draw bin contents for 1-D histogram

Hi,

Is there an equivalent of the TH2::Draw(“text”) option for 1-D histograms? I want to draw the bin contents on a 1-D histogram, but I can’t figure out how. Even just a simple macro would save me time.

-tom

Hi Tom,
I know of a hack. It really looks like a TH1F :-]

TH1F* h=new TH1F("a","a",10,0.,1.); h->FillRandom("gaus"); h2=new TH2F("b","b",10,0.,1.,1,0.,1.); for (int i=0; i<h->GetNbinsX(); i++) h2->SetBinContent(i+1, 1, h->GetBinContent(i+1)); h2->SetMarkerSize(2.4); h2->Draw("TEXT"); h2->GetYaxis()->SetNdivisions(0, kFALSE);
Axel.

You can try the following example and adapt it to your needs. We will try to implement the option “text” for 1-d histograms as well.

Rene

{
TH1F* h=new TH1F(“a”,“a”,30,-1,3);
h->FillRandom(“gaus”);
h->Draw();
//superimpose bin values
Double_t dt = 0.02*(gPad->GetY2()-gPad->GetY1());
TText t;
t.SetTextSize(dt);
t.SetTextAngle(33);
for (Int_t i=1;i<31;i++) {
Double_t xt = h->GetXaxis()->GetBinCenter(i);
Double_t yt = h->GetBinContent(i);
t.DrawText(xt,yt+0.2*dt,Form("%g",yt));
}
}