# Formatting Problems

**URL:** <https://root-forum.cern.ch/t/formatting-problems/41347>\
**Category:** Newbie\
**Created:** [September 8, 2020, 10:25pm UTC](https://root-forum.cern.ch/t/formatting-problems/41347 "2020-09-08T22:25:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [September 8, 2020, 10:25pm UTC](https://root-forum.cern.ch/t/formatting-problems/41347/1 "2020-09-08T22:25:33Z")

</div>

Hello,  
I am making a plot and a residual plot. I am having some formatting problems.

1. The y-axis label on my runner plot is too high.
2. I want the runner plot to span the same width that my main plot does, but now it is not so.
3. I am not sure if the residual plot I made is really plotting data-fit/bin\_error.

Any help is greatly appreciated.

[dummy1.txt](https://root-forum.cern.ch/uploads/short-url/89bjyVUbBAeLKITAPWHY5Oq4JIk.txt) (9.8 KB)  
[alpha\_0\_beta\_and\_C01.txt](https://root-forum.cern.ch/uploads/short-url/nY9xxk5y5UrAvtkPB7UB086JlOg.txt) (785 Bytes)  
[alpha\_0\_beta\_and\_C01.cxx](https://root-forum.cern.ch/uploads/short-url/gGjFrhp4pEwQU1SGQFIRECsSvxS.cxx) (4.1 KB)

* * *

_ROOT Version:_ 6.23/01

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 9, 2020, 9:15am UTC](https://root-forum.cern.ch/t/formatting-problems/41347/2 "2020-09-09T09:15:27Z")

</div>

Looking at it

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 9, 2020, 1:47pm UTC](https://root-forum.cern.ch/t/formatting-problems/41347/3 "2020-09-09T13:47:56Z")

</div>

```auto
void alpha_0_beta_and_C01(){

// gROOT->SetStyle("Plain");
    gStyle->SetOptFit(1111);

   auto c1= new TCanvas("c","BPRE",10,10,600,600);
   c1->Divide(1,1);
   c1->SetTickx();
   c1->SetTicky();
   c1->SetTitle("");
   c1->SetLineWidth(3);
   c1->SetBottomMargin(0.1);
   c1->SetTopMargin(0.05);
   c1->SetRightMargin(0.01);
   c1->SetFillColor(0);
   c1->cd(0);
   TPad* pad1 = new TPad("pad1","pad1",0,0.3,1,0.97);
   pad1->SetBottomMargin(0);
   pad1->SetLeftMargin(0.13);
   pad1->SetRightMargin(0.04);
   pad1->SetTopMargin(0.02);
   pad1->SetGrid();
   pad1->Draw();
   pad1->cd();

   TH1F* h=pad1->DrawFrame(0,-5,360,200);
   h->GetXaxis()->SetRangeUser(0,360);
   auto hh=new TH1F("Statistics" , "" ,36,0.,360.);
   hh->SetMarkerStyle(8);
   ifstream inp; double x;
   inp.open("dummy1.txt");
   while(!(inp >> x)==0){hh->Fill(x);}
   auto graph = new TGraphErrors("./alpha_0_beta_and_C01.txt","%lg %lg %lg %lg");
   graph->SetTitle("Measurement of Coincidence Counts C01 w.r.t. Angle #beta at #alpha=0#circ + Offset; Angle #beta [degrees]; Coincidence Counts");
   graph->SetMarkerStyle(kCircle);
   graph->SetFillColor(0);
   graph->GetYaxis()->SetTitleOffset(1.3);
   graph->Draw("PEA");

   auto g = new TF1("Sinusoidal Fit","(0.5*[0]*((TMath::Cos([1]*(x-[2]))**2)))",0.,360.);
   g->SetParameters(320.0,0.02,5);
   g->SetLineColor(kRed);
   graph->Fit(g,"M","",0.,360.); // graph.Fit(g,"M","SAMES",0.,10.);
   g->Draw("same");

   // Draw the Legend
   auto leg = new TLegend(0.6,0.71,0.8,0.9,"QUED");
   leg->SetFillColor(0);
   leg->AddEntry(graph,"Measured Points");
   leg->AddEntry(g,"Fit");
   leg->Draw(); // leg.DrawClone("Same");
   gStyle->SetOptFit(1111); // Not working...
   auto text = new TLatex(121.4399,21.4941,"f(x)=0.5 #times p_{0}Cos^2(p_{1}(x-p_{2}))");
   text->SetTextSize(0.03114861);
   text->Draw();

   gPad->Update();
   TPaveStats *ps = (TPaveStats*)graph->GetListOfFunctions()->FindObject("stats");
   ps->SetX1NDC(0.3);
   ps->SetY1NDC(0.7);
   ps->SetX2NDC(0.5);
   ps->SetY2NDC(0.9);

   TH1F *DiffHist = new TH1F(*(hh));
   DiffHist->SetFillColor(2);
   TAxis* ay = DiffHist->GetYaxis();
   TAxis* ax = DiffHist->GetXaxis();
   ay->SetTitle("(Data-Fit)/Error");
   ay->CenterTitle(true);
   ay->SetLabelFont(42);
   ay->SetLabelSize(0.10);
   ay->SetTitleSize(0.3);
   ay->SetTitleOffset(0.33);
   ay->SetNdivisions(505);
   ay->SetLabelSize(0.12);
   ay->SetTitleSize(0.1);

   ax->SetTitle("Angle #beta [degrees]");
   ax->SetRangeUser(0,360);
   ax->SetLabelFont(42);
   ay->SetLabelFont(42);
   ax->SetLabelSize(0.12);
   ax->SetTitleSize(0.11);

   for ( int i = 1; i <= DiffHist->GetNbinsX(); i++ ) {
      DiffHist->SetBinContent(i,(hh->GetBinContent(i) -
      g->Eval(hh->GetBinCenter(i)))/(hh->GetBinError(i)));
   }

   TPad* pad2 = new TPad("pad2","pad2",0,0.01,1,0.3);
   c1->cd(1);
   pad2->SetLeftMargin(0.123);
   pad2->SetRightMargin(0.029);
   pad2->SetTopMargin(0);
   pad2->SetBottomMargin(0.31);

   pad2->Draw();
   pad2->cd();

   gStyle->SetOptStat(0);
   DiffHist->Draw();
}

```

 ![Screenshot 2020-09-09 at 15.47.41](https://root-forum.cern.ch/uploads/default/original/3X/f/f/ff6970660f979612bb614cea016a77cfb5d86a8b.jpeg)

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [September 9, 2020, 2:20pm UTC](https://root-forum.cern.ch/t/formatting-problems/41347/4 "2020-09-09T14:20:22Z")

</div>

Thank you couet. Right now it looks nice, but I want it so that the runner plot lines up with the x coordinate of the main plot. Like right now, the top plot goes from x=-40 to x=400, while the bottom one goes from x=0 to x=360, but they span the same width. Is there a way to line up the endpoints of the main plot (x=0 and x=360) with the ends of the runner plot? Like in the image below, except that it is the same width.

 ![Screen Shot 2020-09-09 at 10.18.18 AM](https://root-forum.cern.ch/uploads/default/original/3X/c/2/c2cc091aab250b1a0dd7189f8e85d780aaf18004.jpeg)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 9, 2020, 3:31pm UTC](https://root-forum.cern.ch/t/formatting-problems/41347/5 "2020-09-09T15:31:38Z")

</div>

```auto

void alpha_0_beta_and_C01(){

// gROOT->SetStyle("Plain");
    gStyle->SetOptFit(1111);

   auto c1= new TCanvas("c","BPRE",10,10,600,600);
   c1->Divide(1,1);
   c1->SetTickx();
   c1->SetTicky();
   c1->SetTitle("");
   c1->SetLineWidth(3);
   c1->SetBottomMargin(0.1);
   c1->SetTopMargin(0.05);
   c1->SetRightMargin(0.01);
   c1->SetFillColor(0);
   c1->cd(0);
   TPad* pad1 = new TPad("pad1","pad1",0,0.3,1,0.97);
   pad1->SetBottomMargin(0);
   pad1->SetLeftMargin(0.13);
   pad1->SetRightMargin(0.04);
   pad1->SetTopMargin(0.02);
   pad1->SetGrid();
   pad1->Draw();
   pad1->cd();

   TH1F* h=pad1->DrawFrame(0,-5,360,200);
   h->GetXaxis()->SetRangeUser(0,360);
   auto hh=new TH1F("Statistics" , "" ,36,0.,360.);
   hh->SetMarkerStyle(8);
   ifstream inp; double x;
   inp.open("dummy1.txt");
   while(!(inp >> x)==0){hh->Fill(x);}
   auto graph = new TGraphErrors("./alpha_0_beta_and_C01.txt","%lg %lg %lg %lg");
   graph->SetTitle("Measurement of Coincidence Counts C01 w.r.t. Angle #beta at #alpha=0#circ + Offset; Angle #beta [degrees]; Coincidence Counts");
   graph->SetMarkerStyle(kCircle);
   graph->SetFillColor(0);
   graph->GetYaxis()->SetTitleOffset(1.3);
   graph->Draw("PEA");

   auto g = new TF1("Sinusoidal Fit","(0.5*[0]*((TMath::Cos([1]*(x-[2]))**2)))",0.,360.);
   g->SetParameters(320.0,0.02,5);
   g->SetLineColor(kRed);
   graph->Fit(g,"M","",0.,360.); // graph.Fit(g,"M","SAMES",0.,10.);
   g->Draw("same");

   // Draw the Legend
   auto leg = new TLegend(0.6,0.71,0.8,0.9,"QUED");
   leg->SetFillColor(0);
   leg->AddEntry(graph,"Measured Points");
   leg->AddEntry(g,"Fit");
   leg->Draw(); // leg.DrawClone("Same");
   gStyle->SetOptFit(1111); // Not working...
   auto text = new TLatex(121.4399,21.4941,"f(x)=0.5 #times p_{0}Cos^2(p_{1}(x-p_{2}))");
   text->SetTextSize(0.03114861);
   text->Draw();

   gPad->Update();
   TPaveStats *ps = (TPaveStats*)graph->GetListOfFunctions()->FindObject("stats");
   ps->SetX1NDC(0.3);
   ps->SetY1NDC(0.7);
   ps->SetX2NDC(0.5);
   ps->SetY2NDC(0.9);
   gPad->Modified();
   gPad->Update();

   TH1F *DiffHist = new TH1F(*(hh));
   DiffHist->SetFillColor(2);
   DiffHist->SetLineColor(0);

   for ( int i = 1; i <= DiffHist->GetNbinsX(); i++ ) {
      DiffHist->SetBinContent(i,(hh->GetBinContent(i) -
      g->Eval(hh->GetBinCenter(i)))/(hh->GetBinError(i)));
   }

   c1->cd(0);
   TPad* pad2 = new TPad("pad2","pad2",0,0.01,1,0.3);
   pad2->SetLeftMargin(0.13);
   pad2->SetRightMargin(0.04);
   pad2->SetTopMargin(0);
   pad2->SetBottomMargin(0.3);

   pad2->Draw();
   pad2->cd();

   TH1F *frame = pad2->DrawFrame(-40.,-2.8,400.,2.8);
   TAxis* ay = frame->GetYaxis();
   TAxis* ax = frame->GetXaxis();
   ay->SetTitle("(Data-Fit)/Error");
   ay->CenterTitle(true);
   ay->SetLabelFont(42);
   ay->SetLabelSize(0.10);
   ay->SetTitleSize(0.3);
   ay->SetTitleOffset(0.33);
   ay->SetNdivisions(505);
   ay->SetLabelSize(0.12);
   ay->SetTitleSize(0.1);

   ax->SetTitle("Angle #beta [degrees]");
   ax->SetLabelFont(42);
   ay->SetLabelFont(42);
   ax->SetLabelSize(0.12);
   ax->SetTitleSize(0.11);

   gStyle->SetOptStat(0);
   DiffHist->Draw("SAME");
}

```

 ![Screenshot 2020-09-09 at 17.31.04](https://root-forum.cern.ch/uploads/default/original/3X/7/4/74b29a0c95dd4187ffca5330d023fc795bba4fbf.jpeg)

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [September 9, 2020, 4:02pm UTC](https://root-forum.cern.ch/t/formatting-problems/41347/6 "2020-09-09T16:02:02Z")

</div>

Thank you couet!

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [September 9, 2020, 4:15pm UTC](https://root-forum.cern.ch/t/formatting-problems/41347/7 "2020-09-09T16:15:55Z")

</div>

Why is it when I change the number of bins, it does not work? In the following line:

```auto
   auto hh=new TH1F("Statistics" , "" ,36,0.,360.);

```

If I change from 36 to 37, it does not work.

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [September 10, 2020, 9:15pm UTC](https://root-forum.cern.ch/t/formatting-problems/41347/8 "2020-09-10T21:15:44Z")

</div>

@couet  
Also, do you know how I can change the precision of the displayed parameters? Like make p0  
286 +/- 6 for instance?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 11, 2020, 9:13am UTC](https://root-forum.cern.ch/t/formatting-problems/41347/9 "2020-09-11T09:13:04Z")

</div>

> [@Edward\_Finkelstein](#):
>
> Why is it when I change the number of bins, it does not work?

Because, in that case, some bin (#37) is `-Inf` in the loop at the end of your macro.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 11, 2020, 9:14am UTC](https://root-forum.cern.ch/t/formatting-problems/41347/10 "2020-09-11T09:14:34Z")

</div>

> [@Edward\_Finkelstein](#):
>
> Also, do you know how I can change the precision of the displayed parameters? Like make p0  
> 286 +/- 6 for instance?

I guess @moneta might know. But seems to me that’s a computed error and you cannot impose it.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [September 11, 2020, 9:44am UTC](https://root-forum.cern.ch/t/formatting-problems/41347/11 "2020-09-11T09:44:20Z")

</div>

@couet : I think @Edward_Finkelstein refers on how to change the precision printing in the static box of the fitted parameters. Do you know if this is possible and how to do it ?  
Otherwise one can always change by hand the parameter values and error in the `TF1` object by calling `TF1::SetParameter` and `TF1::SetParError`

Lorenzo

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 11, 2020, 11:13am UTC](https://root-forum.cern.ch/t/formatting-problems/41347/12 "2020-09-11T11:13:03Z")

</div>

May be [https://root.cern/doc/master/classTStyle.html#a90a7b4ccacbcb9e136772a7be297cec4](https://root.cern/doc/master/classTStyle.html#a90a7b4ccacbcb9e136772a7be297cec4)
