Unable to set pad to logarithmic scale using THStack pads

Dear all!

I want to draw several histograms seperately with the help of the “pads” option of THStack. This works fine although I don’t manage to set to logarithmic scale. Please see the following example:

log() {

    TH1* h1 = new TH1F("h1","h1",100,-5,5);
    h1->FillRandom("gaus");
    h1->SetLineColor(kRed);

    TH1* h2 = new TH1F("h2","h2",100,-5,5);
    h2->FillRandom("gaus");
    h2->SetLineColor(kBlue);

    THStack* stack = new THStack("hstack","hstack");
    stack->Add(h1);
    stack->Add(h2);

    c2 = new TCanvas("c2","c2");
    stack->Draw("pads");

    c2->cd(1);

    gPad->SetLogy();
    //gPad->SetLogy(1); // same

    gPad->Modified();
    gPad->Update();

}

If I run it with ROOT 5.30.00 the y axis is not logarithmic but stays linear.

Could you please give me a hint what I’m missing?

Thanks a lot,

Sebastian

{
    TH1* h1 = new TH1F("h1","h1",100,-5,5);
    h1->FillRandom("gaus");
    h1->SetLineColor(kRed);

    TH1* h2 = new TH1F("h2","h2",100,-5,5);
    h2->FillRandom("gaus");
    h2->SetLineColor(kBlue);

    THStack* stack = new THStack("hstack","hstack");
    stack->Add(h1);
    stack->Add(h2);

    c2 = new TCanvas("c2","c2");
    stack->Draw("pads");
    gPad->Update();
 
    c2->cd(1);
    gPad->SetLogy(1);
}

Hi!

Thanks, it works. What’s the general Update()-calling rule?

Best regards,

Sebastian

To act on the pad, in your case set the log scale on it, you need the pad to be created.
In this case you do not create the pad yourself. It is created when the THStack in Paint().
To force the Paint(), Update() should be called.
See the difference between Draw() and PAint() here:
root.cern.ch/drupal/content/graphics-pad