Problems with Negative Y axis in TGraph

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)

Chris,

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.

Rene

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.

Thanks for the quick reply.
Chris

To get the Y axis limits you can do:

    printf("Yaxis limits = %g %g\n", tg->GetYaxis()->GetXmin(),
                                     tg->GetYaxis()->GetXmax());

Hi Oliver,

The code snippet that you posted was the original path that I tried. It returns the same upper and lower bounds in my code.

When I reviewed the TAxis code, it appeared to be using the index, and hence why I asked the question.

So, is there another way of doing it?
Chris

Chris,

For me the code I sent you is working fine. It gives me:

Yaxis limits = -12.6472 0.0588347

Which is exactly what we can see on the plot.

Olivier

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

Oliver,

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?

Thanks
Chris

Hi Chris
Use gPad->GetUymin();
gPad->GetUymax();

Rene

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?

Chris

Chris,

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

Rene

Hi Rene,
Once I got my head around the problem it isn’t as bad as I thought. Thank you for the help.
Chris