I have a very strange occurance. I have a plot with the Y maximum
value of zero and a negative minimum value. When I try to do an axis
find bin, it doesn’t seem to work.
TGraph *tg
Yaxis values 0 to -10
tg->GetYaxis()->Findbin(y)
for any value of y returns 1.
I’ve included some source that demonstrates the problem. minus.C (471 Bytes)
Which bin in Y do you try to find?
When drawing a TGraph, the Paint function creates an intermediate histogram with 100 bins along X and 1 bin along Y. So it is normal that the answer is always 1 in your case.
Depending what you try to do, you can create a TH2F with 100 bins along X and 100 bins along Y, then draw this empty TH2F to set the pad frame.
Hello Rene,
What I am really trying to do is find the viewing limits on the TGraph and impliment a pan feature.
What you say makes sense. The question then becomes, what is the best way to get the viewing limits, on the TGraph object? I thought that getting the TAxis Y had all the proper elements.
Hi Oliver,
I just went back and it worked in the macro.
For some reason in my actual compiled code this doesn’t work. So, I have to dig some more. I must have set some bit somewhere. User error!
Thanks for the help. Sorry to inconvinece you.
Chris
Sorry about the confusion, I lost the thread of what it was I was trying to get at. I’m actually trying to see what the upper and lower limits being displayed on the TGraph, not the maximum and minimum values set on the TAxis.
Rene’s answer tells me why my idea to get the displayed upper and lower limits on the TGraph doesn’t work.
If I have zoomed on an axis, what is the best way to get the upper and lower limits of the axis on the display?
Rene,
That suggestion works very well.
What drove me crazy is believing that all information could be gotten through the TAxis class. However, using that thought it required different treatment for X vs Y type axes. X axis use the the GetMinBin, and Y axis uses h->GetMinimum.
So your solution ends up being much better in general.
Thank you!
I do have one additional question which I don’t think has a simple answer, I have looked at Oliver’s replies to other messages about inverting axes. I can invert the axis and then index the array data in reverse. However, is there a mirror type function for the Y-axis that preserves the array but inverts the axis and plotting?
The possibility to invert an axis is implemented in TGaxis (the class used
to paint a TAxis), but there is no interface in TAxis because inverting a TAxis also implies to paint the bins in reverse order (something we want to implement).
To see how to draw a TGaxis in reverse order, see tutorial gaxis.C