TVirtualPad Documentation (Drawing lines that stay in frame.)

Does anyone have any clarification on what TVirtualPad::GetRange and TVirtualPad::GetRangeAxis do?

I’m looking to replace TLine objects drawn from TVritualPad::GetUxmin to TVirtualPad::GetUxmax (also not documented) with TGraphs that extend across the maximum limit of the axis that was set with TAxis::SetLimits (also not documented). It seems that gPad does not permit easy access to the TAxis object drawn on that pad. Any susggestions would be appreciated.

These two methods are implemented in TPad and what they return is explained here

TAxis are (is histogram has at least two) members of TH1 (for instance). They are not drawn by themselves. If you do gPad->ls() after having drawn an histogram you will not see any TAxis in the list of Primitives. They are painted by THistPainter thanks to TGaxis

Thanks for the quick response, I should have clicked the ‘Implemented in TPad’ link.

Secondly, I understand that the TAxis is not a primitive, will TVirtualPad::GetRangeAxis return the limits of the axis or the currently zoomed values as TVirtualPad::GetUxmax etc. do? Sorry the one line documentation does not always provide the most clear description.

Return pad axis coordinates range.

Is it better that I just draw the line from std::numeric_limits<double>::min() to ...max() and not worry about the axis?

Also, in general I find the @param command of doxygen very useful for documenting what every parameter is expecting or returning. I’d love to see ROOT start adopting this in the documentation.

GetRangeAxis returns the range of the axis of the current plot on a Pad:

root [0] hpx->Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [1] double xmin,xmax,ymin,ymax;
root [2] gPad->GetRangeAxis(xmin,ymin,xmax,ymax);
root [3] printf("%g %g %g %g \n",xmin,xmax,ymin,ymax);
-4 4 0 851.55 

Thanks for the example. Looks like this does exactly the same as TVirtualPadd::GetUxmin() etc..

I agree with you. I am trying to do the conversion as much as I can. That’s not something which can be done automatically. The current doxygen documentation comes from the previous THTML version in which @param did not exist.

The following worked for drawing lines that go from -inf to +inf that do not leave the frame as the axis is scaled and with no need to deal with gPad.

#include <limits>
#include <vector>

#include <TGraph.h>

void DrawLines(const std::vector< double > &axisValues, const bool &vertical) {
   std::vector< double > xValues(2), yValues(2);
   if (vertical) {
      yValues.at(0) = std::numeric_limits< double >::min();
      yValues.at(1) = std::numeric_limits< double >::max();
   }
   else {
      xValues.at(0) = std::numeric_limits< double >::min();
      xValues.at(1) = std::numeric_limits< double >::max();
   }

   TGraph *line = new TGraph();
   for (auto axisValue : axisValues) {
      if (vertical)  xValues.at(0) = xValues.at(1) = axisValue;
      else  yValues.at(0) = yValues.at(1) = axisValue;
      line->DrawGraph(2, xValues.data(), yValues.data(), "L");
   }
}

(Replacing TLine with TGraph inspired from Problem with TLine and resizing of x-axis)

Ok … So there a problem somewhere ?

The problem, was simply the documentation. It was not clear to me how to get the limits of the axis (not just the current zoom, but the full extent of the axis limit) when just provided with gPad.

I instead went ahead and simply set the line limits at the maximum and minimum possible values, so the line is drawn no matter what the axis is set to. This requires no interaction with the drawn primitive or the pad and should work in any situation.

Thanks for your clarification on the methods.

You are welcome. :slight_smile:

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