# Set LogScale on Z axis in 2D histo

**URL:** <https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385>\
**Category:** ROOT\
**Created:** [July 3, 2017, 11:10am UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385 "2017-07-03T11:10:21Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![diboye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@diboye](https://root-forum.cern.ch/u/diboye)\
**Post date:** [July 3, 2017, 11:10am UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/1 "2017-07-03T11:10:21Z")

</div>

Dear All,  
I would like to plot a 2D histo using colz option (let’s say the background) and on top of it I plot the signal using box option. It works pretty well but if I set z axis in logscale by doing for instance this:

```auto
 c1->SetLogz();

```

the signal disappears. Can someone tell me please how to resolve it?  
Thanks in adavance.  
Cheers

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [July 3, 2017, 11:25am UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/2 "2017-07-03T11:25:33Z")

</div>

Warnings concerning a “logarithmic palette” (maybe it’s just TGraph2D specific) … I think this problem has not been fixed: [Number of divisions on palette](https://root-forum.cern.ch/t/number-of-divisions-on-palette/12237/7)

---

<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:** [July 3, 2017, 11:40am UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/3 "2017-07-03T11:40:27Z")

</div>

I will look at it. thanks

---

<div class="post-metadata">

**Author:** ![diboye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@diboye](https://root-forum.cern.ch/u/diboye)\
**Post date:** [July 3, 2017, 11:48am UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/4 "2017-07-03T11:48:57Z")

</div>

Hi,  
Thanks for replying, hope there will be a solution 🙂 .  
Cheers  
Diallo

---

<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:** [July 3, 2017, 12:37pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/5 "2017-07-03T12:37:10Z")

</div>

I tried the following and it seems ok:

```auto
void colcontsame() {
   TH2F *h1 = new TH2F("h1","h1",100,-10,10,100,-10,10);
   TH2F *h2 = new TH2F("h2","h2",40,-3,3,40,-3,3);
   for (Int_t i=0;i<1000;i++) {
      double x,y;
      gRandom->Rannor(x,y);
      h1->Fill(5*x,5*y,4);
      if(x<0 && y<0) h2->Fill(x,y,3);
   }
   h1->SetFillColor(1);
   h2->SetLineColor(kRed);
   h2->SetContour(5);
   h1->Draw("col");
   h2->Draw("cont3 same");
   gPad->SetLogz();
}

```

replacing `cont3` by `box` seems fine too.

---

<div class="post-metadata">

**Author:** ![diboye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@diboye](https://root-forum.cern.ch/u/diboye)\
**Post date:** [July 3, 2017, 12:45pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/6 "2017-07-03T12:45:18Z")

</div>

Hi,  
Thanks so much it works with cont 3 option 🙂  
Cheers  
Diallo

---

<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:** [July 3, 2017, 12:46pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/7 "2017-07-03T12:46:51Z")

</div>

As I said box option is fine too in that case.

---

<div class="post-metadata">

**Author:** ![diboye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@diboye](https://root-forum.cern.ch/u/diboye)\
**Post date:** [July 3, 2017, 12:50pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/8 "2017-07-03T12:50:00Z")

</div>

HI,  
If I put box instead of cont3 the bar will appear with logScal but the signal is not plotted.  
Cheers  
Diallo

---

<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:** [July 3, 2017, 12:53pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/9 "2017-07-03T12:53:02Z")

</div>

Ok … to help further I would need a example.  
With my macro both box and cont3 are fine.

---

<div class="post-metadata">

**Author:** ![diboye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@diboye](https://root-forum.cern.ch/u/diboye)\
**Post date:** [July 3, 2017, 1:06pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/10 "2017-07-03T13:06:43Z")

</div>

Ok here is the code for instance:

```auto
 TFile* f2 = new TFile("/afs/cern.ch/user/d/diboye/diboye_work/ZdZdTruthArea/run/Plots/Mzd50GeV_Gamma4MeV_KinVar_ACC.root");
 TFile* f8 = new TFile("/afs/cern.ch/user/d/diboye/diboye_work/ZdZdRecoArea/run/Diamoond_Square_Circle_Bkg/bkg_ggFH_KinVar_ACC.root");
 TH2D * Hist_M12vsM34_ACC = (TH2D*)f2->Get("myHist_M12vsM34_all");
   Double_t scale48 = 1/Hist_M12vsM34_ACC->Integral();
   Hist_M12vsM34_ACC->Scale(scale48);
   Hist_M12vsM34_ACC->SetFillColor(1);
   Hist_M12vsM34_ACC->SetMarkerColor(1);
 TH2D * Hist_M12vsM34_ACC_bkg_ggFH = (TH2D*)f8->Get("myHist_M12vsM34_all");
   Double_t scale54 = 1/Hist_M12vsM34_ACC_bkg_ggFH->Integral();
   Hist_M12vsM34_ACC_bkg_ggFH->Scale(scale54);
   Hist_M12vsM34_ACC_bkg_ggFH->SetFillColor(4);
  gStyle->SetPalette(55);
   Hist_M12vsM34_ACC_bkg_ggFH->GetXaxis()->SetTitle("M_{34}[GeV]");
   Hist_M12vsM34_ACC_bkg_ggFH->GetYaxis()->SetTitle("M_{12}[GeV]");
    Hist_M12vsM34_ACC->SetContour(5);
     Hist_M12vsM34_ACC->SetLineColor(1);
       Hist_M12vsM34_ACC_bkg_ggFH->Draw("colz");
       Hist_M12vsM34_ACC->Draw("box same");
       c1->SetLogz();

```

[bkg\_ggFH\_KinVar\_ACC.root](https://root-forum.cern.ch/uploads/default/original/2X/a/a97dd7df7d7254fff2541c445bfd1b8cea13ffc2.root) (15.0 KB)  
[Mzd50GeV\_Gamma4MeV\_KinVar\_ACC.root](https://root-forum.cern.ch/uploads/default/original/2X/8/8aebbe791531b2be5efa8ef3034f408a25ffc059.root) (117.4 KB)  
I uploaded a part of my macro which is supposed to do the job with the files.  
Cheers  
Diallo

---

<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:** [July 3, 2017, 1:19pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/11 "2017-07-03T13:19:04Z")

</div>

I do not know why but:

```auto
{
   TFile* f2 = new TFile("Mzd50GeV_Gamma4MeV_KinVar_ACC.root");
   TH2D * Hist_M12vsM34_ACC = (TH2D*)f2->Get("myHist_M12vsM34_all");
   Double_t scale48 = 1/Hist_M12vsM34_ACC->Integral();
   Hist_M12vsM34_ACC->Scale(scale48); // if you comment this line then the box option works with logz
   Hist_M12vsM34_ACC->Draw("box ");
   c1->SetLogz();
}

```

---

<div class="post-metadata">

**Author:** ![diboye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@diboye](https://root-forum.cern.ch/u/diboye)\
**Post date:** [July 3, 2017, 1:34pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/12 "2017-07-03T13:34:01Z")

</div>

Hi,  
You are right, it’s a bit strange but it works like that, the same also for “scat” option.  
Cheers  
Diallo

---

<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:** [July 3, 2017, 2:05pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/13 "2017-07-03T14:05:15Z")

</div>

I am investigating why it does not show in case of box

---

<div class="post-metadata">

**Author:** ![diboye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@diboye](https://root-forum.cern.ch/u/diboye)\
**Post date:** [July 3, 2017, 4:35pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/14 "2017-07-03T16:35:07Z")

</div>

Ok Thanks in advance 🙂

---

<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:** [July 4, 2017, 1:21pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/15 "2017-07-04T13:21:54Z")

</div>

This problem now fixed in the ROOT master.

---

<div class="post-metadata">

**Author:** ![diboye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@diboye](https://root-forum.cern.ch/u/diboye)\
**Post date:** [July 4, 2017, 1:44pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/16 "2017-07-04T13:44:19Z")

</div>

Hi  
Thanks very much, really appreciate 🙂

---

<div class="post-metadata">

**Author:** ![diboye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@diboye](https://root-forum.cern.ch/u/diboye)\
**Post date:** [July 4, 2017, 1:51pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/17 "2017-07-04T13:51:36Z")

</div>

By the way did you try with the code I sent you? didn’t manage yet to use box option with the line uncomment

---

<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:** [July 4, 2017, 1:54pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/18 "2017-07-04T13:54:04Z")

</div>

> [@diboye](#):
>
> By the way did you try with the code I sent you? didn’t manage yet to use box option with the line uncomment

That was the bug I fixed in the master …

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [July 18, 2017, 1:54pm UTC](https://root-forum.cern.ch/t/set-logscale-on-z-axis-in-2d-histo/25385/19 "2017-07-18T13:54:15Z")

</div>

Closed on July 18, 2017, 1:54pm UTC

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