Option "TEXTE" for 1D histograms

Hello,

from ROOT: THistPainter Class Reference I see that I can use the drawing option “TEXTE” to get the bin error also printed with the bin content, but only for 2D histograms.
I wonder if there is any straightforward way to have the same, but on 1D histograms.
I know I can achieve a similar result by following the trick shown here SetPaintTextFormat - #6 by couet, but if the “TEXTE” option can also be implemented on TH1s I believe it will be very nice…

Thanks!
Cheers,
Mateus

Indeed, right now, the option TEXTE does “something” for 1D histograms. It draws the histogram with error bars and with text simultaneously. Do you want to change this behavior ?

Thank you for the fast reply!
If possible, in addition to the bin content text, we could also have the ± bin error text (as the TH2 in the screenshoot attached).

Yes I understand that. But now the option TEXTE, used for 1D histograms, does already something (just try) which is not what you ask. If we implement what you are asking the current behavior will disappear.

I already like what TEXTE does on TH1. The point is, in addition to the error bar and bin_content text, can we have the error text optionally displayed (“TEXTEE”) (as the text in red photoshopped on top of the original plot bellow)?

So that’s a new option, no the implementation of TEXTE for 1D histograms. I would suggest you open a GitHub issue so we do not forget about this request,

Will do! Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

Indeed it is quite simple to produce this option with the existing ROOT. Maybe we do not need more than that:

void histtext() {
   auto c = new TCanvas("c","A Simple histogram Example with Text",700,500);
   TH1F *h1 = new TH1F("h1","Histogram drawn with customised text",10,-3,3);
   Int_t i;
   for (i=0;i<10000;i++) h1->Fill(gRandom->Gaus(0,1));

   TExec *ex = new TExec("ex","DrawText();");
   h1->GetListOfFunctions()->Add(ex);
   h1->Draw("E");
}


void DrawText()
{
   Int_t i,n;
   Double_t x,y,w,e;
   TLatex *lc,*le;

   TH1F *h = (TH1F*)gPad->GetListOfPrimitives()->FindObject("h1");
   n = h->GetNbinsX();
   for (i=1; i<=n; i++) {
      x = h->GetBinCenter(i);
      y = h->GetBinContent(i);
      w = h->GetBinWidth(i);
      e = h->GetBinError(i);
      lc = new TLatex(x-w/6,y,Form("%4.2f",y));
      lc->SetTextSize(0.025);
      lc->SetTextAngle(90.);
      lc->SetTextFont(42);
      lc->SetTextAlign(12);
      lc->Paint();
      le = new TLatex(x+w/6,y,Form("#pm%4.2f",e));
      le->SetTextSize(0.025);
      le->SetTextAngle(90.);
      le->SetTextAlign(12);
      le->SetTextColor(kRed);
      le->SetTextFont(42);
      le->Paint();
   }
}

1 Like