Anchor TGaxis in a fixed position and zoom

Dear all,

I am using an old version of root (5.34/36) because I need a windows environment.
I had to reverse the axis of my TH2 graphs, therefore I successfully set a macro which creates TGaxis objects replacing the standard TH2 axis.
When I try to zoom in the final graph, the TGaxis move according to the zoom. I would like to anchor these two objects to the underlying TH2 or to give them an absolute position. Is it possible?
Here the piece of the code, taken from reverseaxis.C, which I found on this very forum.

gui_newCanvas();
	reversedHist->Draw("COLZ");
	
	//reversin the AXIS. It is just lable stuff, not organic reversing
	// Remove the current axis
	
    reversedHist->GetXaxis()->SetLabelOffset(999);
    reversedHist->GetXaxis()->SetTickLength(0);
    
    // Redraw the new axis
    gPad->Update();
    TGaxis *newXaxis = new TGaxis(gPad->GetUxmax(),
                           gPad->GetUymin(),
                           gPad->GetUxmin(),
                           gPad->GetUymin(),
                           reversedHist->GetXaxis()->GetXmin(),
                           reversedHist->GetXaxis()->GetXmax(),
                           510,"-");
	newXaxis->SetTitle(original->GetXaxis()->GetTitle());
	newXaxis->SetTitleSize(0.02);
	newXaxis->SetTitleOffset(1.5);
	newXaxis->SetLabelOffset(-0.03);
	newXaxis->SetLabelSize(0.03);
    newXaxis->Draw();

PS. is there a way to center the Lables respect to the axis?

Thank you for you time!

LG,


Please read tips for efficient and successful posting and posting code

ROOT Version: 5.34/36
Platform: Windows 10
Compiler: VS2010


The TGaxis position is set according the Pad coordinates when they change the TGaxis position should be also changed if you want the axis to follow the pad. The way to do that is to draw the Axis in a TExec.

Hi! Thank you for your reply. I have skimread the documetnation on the TExec. Do you have example to suggest me on how to use TExec instead of TGaxis?

LG,

here is a simple demonstrator.
texec_axis.C (358 Bytes)

Hi,
I have a class which I guess does what you are looking for:

HprGaxis.h (1.5 KB) HprGaxis.cxx (4.7 KB)

I’d be happy if somebody else debugs it,
that means exploits Murphys phasespace for bugs

Otto

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