# Log scale does not work

**URL:** <https://root-forum.cern.ch/t/log-scale-does-not-work/53245>\
**Category:** Newbie\
**Created:** [January 24, 2023, 4:01pm UTC](https://root-forum.cern.ch/t/log-scale-does-not-work/53245 "2023-01-24T16:01:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Progressive](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/dfb087/32.png) [@Progressive](https://root-forum.cern.ch/u/Progressive)\
**Post date:** [January 24, 2023, 4:01pm UTC](https://root-forum.cern.ch/t/log-scale-does-not-work/53245/1 "2023-01-24T16:01:40Z")

</div>

* * *

_ROOT Version:_ 6.26/02  
_Platform:_ Windows  
_Compiler:_ MSVC 19.31.31104.0

* * *

Hi,

I can’t get it done to plot an axis logarithmically. The code is:

```auto
	Double_t partEdep;	
	tree = myFile->Get<TTree>("depE_sum");
	tree->SetBranchAddress("fdepEnergy_sum", &partEdep);
	auto HdepEnergy = new TH1F("HdepEnergy", "Histo_depE", 10000, 0.0001, 1.);  
	for (int iEntry = 0; iEntry < tree->GetEntriesFast(); ++iEntry)
	{
		tree->GetEntry(iEntry);
		HdepEnergy->Fill(partEdep);
	}

	TCanvas* c2 = new TCanvas("c2", "", 20, 20, 1000, 500);
	c2->Divide(1,4);

	c2->cd(1);
	c2->SetLogx();
	HdepEnergy->Draw("EHIST");
	HdepEnergy->SetFillColor(kCyan-2);
	HdepEnergy->SetLineColor(kOrange-3);
	HdepEnergy->GetXaxis()->SetTitle("[keV]");
	c2->SetLogx();

```

It’ll always plot regularly. Could you please tell me what I am doing wrongly?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 24, 2023, 4:05pm UTC](https://root-forum.cern.ch/t/log-scale-does-not-work/53245/2 "2023-01-24T16:05:27Z")

</div>

`gPad->SetLogx();`

---

<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:** [January 24, 2023, 4:09pm UTC](https://root-forum.cern.ch/t/log-scale-does-not-work/53245/3 "2023-01-24T16:09:45Z")

</div>

You can also change:

```auto
c2->cd(1);
c2->SetLogx();

```

to:

```auto
c2->cd(1)->SetLogx();

```

and remove `c2->SetLogx();`

---

<div class="post-metadata">

**Author:** ![Progressive](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/dfb087/32.png) [@Progressive](https://root-forum.cern.ch/u/Progressive)\
**Post date:** [January 27, 2023, 7:49am UTC](https://root-forum.cern.ch/t/log-scale-does-not-work/53245/4 "2023-01-27T07:49:33Z")

</div>

Thank you, this worked! But why? Respectively why does this work and not the other way around?

---

<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:** [January 27, 2023, 9:00am UTC](https://root-forum.cern.ch/t/log-scale-does-not-work/53245/5 "2023-01-27T09:00:13Z")

</div>

You have several pads. You need to set the log scale on the right pad. It was not the case in your initial code.
