Custom TGAxis working with colz but disappearing with cont4z

Hi all,

I have a custom TGAxis which shows up at the right position if the 2D histogram is drawn with “colz” but disappears if it is drawn with “cont4z”. Any ideas to solve that issue?

void Axis() {

TH2D* H = new TH2D("H", "H", 24, -3, 3, 24, -3, 3);
for (unsigned int i = 0; i < 100000; ++i) {
  H->Fill(-2 + 4*gRandom->Rndm(), -2 + 4*gRandom->Rndm());
}

TCanvas* C = new TCanvas();
C->cd();
C->Range(-3, -3, 3, 3);

//H->Draw("colz");      // works
H->Draw("cont4z");    // does not work

TGaxis* YAxis = new TGaxis(gPad->GetUxmin(),
                           gPad->GetUymax(),
                           0.9999*gPad->GetUxmin(),
                           gPad->GetUymin(),
                           H->GetYaxis()->GetXmin(),
                           H->GetYaxis()->GetXmax(), 510, "-S");

YAxis->ImportAxisAttributes(H->GetYaxis());
YAxis->CenterTitle(true);
YAxis->SetTitle("New");
YAxis->SetLabelOffset(-0.03f);
YAxis->SetTickLength(0.015f);
YAxis->SetTitleOffset(-1.5f);

// Remove the current axis
H->GetYaxis()->SetLabelOffset(999);
H->GetYaxis()->SetTickLength(0);

// Draw the new axis
YAxis->Draw();

C->Update();
C->SaveAs("Axis.pdf");
}

Thanks,
Andreas


ROOT Version: 6.24.06
Platform: Mac OS 12.6
Compiler: Xcode default


CONT4 has its own coordinate system which is not the one displayed on the axis. To superimpose something on a CONT4 contour you need another pad on top of the plot. For instance:

{
   TCanvas cc("cc", "cc");

   TFile f("hsimple.root");
   hpxpy->Draw("cont4");
   gPad->Update();

   Double_t BM = gPad->GetBottomMargin();
   Double_t LM = gPad->GetLeftMargin();
   Double_t RM = gPad->GetRightMargin();
   Double_t TM = gPad->GetTopMargin();
   Double_t X1 = hpxpy->GetXaxis()->GetXmin();
   Double_t Y1 = hpxpy->GetYaxis()->GetXmin();
   Double_t X2 = hpxpy->GetXaxis()->GetXmax();
   Double_t Y2 = hpxpy->GetYaxis()->GetXmax();

   TPad *null=new TPad("null","null",0,0,1,1);
   null->SetFillStyle(0);
   null->SetFrameFillStyle(0);
   null->Draw();
   null->cd();
   null->Range(X1-(X2-X1)*(LM/(1-RM-LM)),
               Y1-(Y2-Y1)*(BM/(1-TM-LM)),
               X2+(X2-X1)*(RM/(1-RM-LM)),
               Y2+(Y2-Y1)*(TM/(1-TM-LM)));

   gPad->Update();
   hpxpy->DrawClone("cont3 same");
}

Thanks for tip!

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