When I draw a graph on a pad, it seems to include some empty space to the left and right of the actual data range on the x-axis. What do I do to display the graph exactly from xmin to xmax as specified in the data range supplied to the graph?
2)I have to display a set of graphs/multigraphs on a screen such that their x axis always display the same range. This should also hold when one of the axis is zoomed. But when i call setRange with same bin numbers on all these axis, they seem to be displayed slightly differently, the ticks do not remain aligned. I supply the same set of x axis values to all these graphs/multigraphs. Any solution?
Thanks for the previous answers.
Related question…
After I display a set of TMultiGraphs each inside a sub-pad under the main canvas, i need to show the y axis values of the constituent graphs in some pavelabels on mouse movement. The Y values should correspond to the x position of the mouse. I use the following piece of code to translate the pixel position to X values on the axis…
Now the following piece of code doesnt seem to work to get the Y values on each graph inside the multigraphs
[color=#0000BF][size=85]Int_t bin = multiGraph->GetXaxis()->FindFixBin(xVal);
//repeat for each graph inside the multiGraph, but this returns 0
graph->GetHistogram()->GetBinContent(bin)[/size][/color]
The following two statements return a vlaue of 1
What am I doing wrong?
I tried graph->Eval(xVal) but that seems to be a time consuming calculation and consumes some serious CPU bandwidth if the graphs have a lot of data.
Well, I am attaching a smaller version of my program here, maybe i’m doing something wrong in the bigger picture. Compiling and running CreateDisplay() from the prompt will show what im trying to do…
Might I draw your attention to the following function in the class TCustomCanvas. Here if I use
[color=#0000BF][size=85]TString Label = TString(gr->GetName())+ (TString(" : “)+= ([b]gr->GetHistogram()->GetBinContent/b));[/size][/color]
instead of
[color=#0000BF][size=85]TString Label = TString(gr->GetName())+ (TString(” : ")+= ([b]gr->Eval/b));[/size][/color]
, I get all zeros in the display.
Tried this, didnt have any effect.
Apologies for piling up the big program on you earlier, I did it to be on the safe side so as to not omit anything. Basically the program compiles a set of multigraphs(a set of graphs inside each), that display time series data. X axis represents time series of course and is zoomable by a mouse drag accross any one of the axis.
Quite puzzling that gr->GetHistogram()->GetBinContent(bin) returns 0 all the time, even though the graphs are being displayed correctly as part of their multigraphs.
Actually this cannot work on TMultigraph because the histogram you get, when you call GetHistogram() on a TMultigraph, is empty. It is just there to define the frame.
Well if you look at the things I tried, I tried it also by retrieving the graphs from the multigraph(bold underlined below), GetBinContent seems to return 0 even for the graphs…
When graphs are in a TMultigraph there no histogram created for each of them, but only a global one for the whole multigraph. And even if you plot a graph alone, the histogram created in background is there to draw the axis only and is empty as the following example demonstrates it:
{
TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);
const Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2)-5;
}
gr = new TGraph(n,x,y);
gr->Draw("A*");
gPad->Update();
gr->GetHistogram()->Draw("SAME HIST");
}
Related question… A multigraph->GetHistogram() returns a TH1F, but a TH1F can represent y axis values for only one graph right? What happens when there are multiple graphs present in the multigraph…
I am probably missing some piece of the picture here…
Yes you are. I the case of TMultigraph one single histogram is computed for all the graphs is a such way that all the graphs fits in the range. Thats the idea of TMultigraph
Okay.
my original problem remains unsolved though… allow me to re-phrase it.
Lets say I have a pointer to a pad on which a multigraph has been drawn with several graphs inside it. Given a mouse pixel X location would I be able to determine the correponding Y values of each of those graphs?