Axis's ticks hidden when drawing histogram with "same"

Hi,
This is very simple: When I plot one histogram (with a solid fill pattern) using “same”, the ticks on the axis are left behind and one cannot see them.
Here to illustrate the example:

{
  TCanvas *C = new TCanvas("C","",800,600);

  gStyle->SetOptStat(0);

  TH1F *h1 = new TH1F("h1","",200,-5,5);
  h1->SetFillStyle(1001);
  h1->SetFillColor(38);  
 
  TH1F *h2 = new TH1F("h2","",200,-5,5);
  h2->SetFillStyle(1001);
  h2->SetFillColor(kGray+1);

  Double_t a,b;
  for (Int_t i=0;i<1e6;i++) {
    gRandom->Rannor(a,b);
    h1->Fill(a-1.5);
    h2->Fill(b+1.5);
  }
  
  gPad->SetGridy();
  gPad->SetGridx();

  h1->Draw();
  h2->Draw("same");
}

This also happens in 2D histograms.
Is there a way to put the axis lines and ticks on top of all the other objects drawn in the canvas?
It would be nice to have the grid lines on top too. Any help?
Cheers.

gPad->RedrawAxis(); // in the end of your macro

1 Like

Oh! thanks!
And anything similar for the grid lines? To make them always on top?
Cheers!

I believe the problem is that you are using a “solid” fill style (i.e. “1001”) for your histograms (btw. it’s the “default” so you should not need to set it “explicitly”).
As a brutal fix … try to “SetFillStyle(3001);” for both your histograms, “h1” and “h2” (instead of “1001”).
See http://root.cern.ch/root/html/TAttFill.html for details.
Maybe Olivier knows a better solution.

For the grid do:

gPad->RedrawAxis(“G”);

to do both call it twice.

  1. without option G
  2. with option G

Thank you! saved me:wink:

1 Like