Automatic repositioning of TGaxis after zooming

I frequently use either a vertical or a horizontal TGaxis to create a secondary axis to my TGraphs or histograms. See attached ROOT file example. example.root (1.7 MB)

The issue: If I zoom on X, the TGaxis disappears.

I would like to propose a new feature, namely a static function TGaxis::SetAutozoom()

  • If TGaxis is vertical (parallel to Y) and drawn on the right border of the frame, if I zoom by hand on X, the TGaxis disappears. However, if I call autozoom first, then the TGaxis x position is recalculated in order to preserve the position in the screen. In other words, that the X position keeps the relative position to the frame.
  • If TGaxis is horizontal and I zoom in the Y axis, the same, it should keep the relative Y position with respect to the frame, not the initially passed UserY position.

What do you think @couet?

Or maybe as an extra drawing option “ZX”, or “ZY” is active, then Y or X are treated as relative frame coordinates rather than user coordinates.

I tried to do something similar with superimposing two TPads, but then only one of them zooms. So another way would be to activate zoom synchronisation between two superimposed pads.

Thanks for your input. I will check your example and what can be done. Instead of a root file do you have a .C macro ?

With this example you can zoom the X axis and the added axis doe not disappear:

TGaxis *ax;

void texec_axis(void){
   TCanvas *c =new TCanvas();
   ax = new TGaxis();
   TExec *draw_axis = new TExec("draw_axis","draw_axis()");
   c->DrawFrame(-1, 600, 1, 750);
   draw_axis->Draw();
}

void draw_axis()
{
   double wmin = 0.;
   double wmax = 30.;
   int ndiv = 510;
   ax->SetLabelFont(42);
   ax->SetLabelColor(kRed);
   ax->PaintAxis(gPad->GetUxmin(),680.,gPad->GetUxmin(),710.,wmin,wmax,ndiv);
}


Thanks a lot for the idea!

However my plots are stored in ROOT files, so I cannot use it from a TBrowser to zoom through old files. Could this TExec trick be automatically added if I right click on the TGaxis and ActivateRezoom or something like that?

If you draw the TGaxis using TExec as I showed it will be stored in the TCanvas so in principle when you save the canavs to a ROOT file and display it afterwards it should be there.

May be you do not have access to the macro which created the cnavs ? or cannot regenerate the plot ?

Exactly, this plot was generated by a data acquisition system one year ago. I have 300 of them stored in separate ROOT files. Activating the TExec script for each of them would require quite some work and would not be easy to do from a TBrowser, so I was thinking of that solution to right click on the TGaxis first to turn on an option that converts X or Y position to relative frame position instead of user coordinates

I see… Not sure how easy/difficult it is to implement… I was trying to retrieve the TGaxis from the canvas but it does not have a name and it is not easy to use FindObject on lit in that case.

Thanks. How is it done for a TLegend? When I zoom in, it stays in the same place. For TGaxisVertical we would need something hybrid, it stays at same place in X but gets adapted in Y if you zoom.

I was thinking about that. Indeed, the objects which do not move have the ability to define their position using NDC coordinates. TGaxis lacks this capability. We could consider adding this feature, but it wouldn’t help with existing axes. Unless, we introduce something like a ConvertX/YPositionToNDC function.

It sounds like the way to go for the future. I don’t mind leaving the old data as is, but as we are actively using this DAQ system, it would be great if at some point TGaxis introduced support for this :slight_smile: so that newly stored ROOT files can be zoomed with TBrowser

That needs more thoughts. I cannot promise it will be feasible. I will look.

1 Like

Indeed TGaxis has already a SetNDC method inherited from TLine. If we turn it ON on a TGaxis it doesn’t do anything right… May be that’s a possibility.

2 Likes

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