Help with plotting multiple histograms in one plot with logarithmic scale with an offset

Hello Root Experts,

I am trying to plot multiple histograms in one plot. I have converted the yaxis of each histogram to logscale individually. However, when I try to plot all these histograms in one single plot, I do not get the logscaled yaxis, instead, I just get the normal y axis in the stacked plot.
Also, I wanted to plot each of these histograms in logscale with a small offset on y axis. Is there a was of doing that?
Here is what I was trying to do-

TH1F *hStackedPlots = new TH1F(“hStackedPlots”, “Excitation Energy Vs Counts”,801,0,20);

TCanvas *cStackedPlots = new TCanvas(“cStackedPlots”, “cStackedPlots”);




hStackedPlots->Draw("hist 1 same");



hdisk126->Draw("hist 1 same");



I also tried using a for loop for the logscale offset by multiplying a constant to each of the bincontent to induce a shift in yaxis, but nothing seems to work.
I am sure there is a smart way to do this. Can anyone help? Thank you for your time and help! Appreciate it!


ROOT Version: 6.18/04
Platform: C++
Compiler: Visual Studio Code


1 Like

Hi @Wile_E_Coyote, Thank you for getting back so quickly. This really helped. I just have one question.

When I stack the log scale plots with an offset, the yaxis is not getting converted to log when I try to stack them. The individual plots do plots by logscale though. This is what I wrote-

// Plotting individual plots first-
TFile* inp = TFile::Open("/root_v6.18.04/macros/HandOff/AlThin/Next steps/Disk118.ROOT");


    TH1F* hdisk118 = (TH1F*)inp->Get("Disk118");

    TCanvas *cdisk118 = new TCanvas("cdisk118","cdisk118");



    hdisk118 -> Draw("hist");
... <doing the same for other plots >...
THStack *hs = new THStack("hs","Excitation Energy vs Counts Spectrum_All data stacked");


 for(Int_t i=0; i< 801; i++){

        Int_t channel = i;

        double Counts = hdisk126->GetBinContent(i);

        Int_t shift = Counts + 1000; //Giving offset

        hdisk126->SetBinContent(channel, shift);




This does give the offset but the y-axis is still not in logscale for some reason. I know it must be a silly mistake. Can you please help?
Thank you for your time and help. Really appreciate it!


Can you post a running macro reproducing the problem? I do not see any thin obviously wrong in the piece of code you posted. You do not Draw the stack. is it intended?

You should have something like this:

hs->Draw("HIST NOSTACK");
1 Like

Thank you @Wile_E_Coyote.
This worked like magic.