Matthew R. Nelson wrote: > > Dear Rooters, > > I would like to add a TPad to a TGraph, with the location of the TPad > being specified by the XY coordinates of the TGraph. The methods for > placing a TPad are relative to the coordinates of the next pad up in the > hierarchy, which in my case is the TCanvas. > > Is there a way to either > a) place a TPad on a TGraph using the TGraph XY coordinates, or > b) obtain a translation of a pair of XY coordinates to the mother > TPad/TCanvas coordinates? > > I suppose as a last resort, all of the TGraph margins and the X and Y > ranges could be considered to create such a translation by hand, but I > would like to avoid that if possible. > Hi Matt, In the attachment, you will find the Root tutorial example graph.C modified to add a pad connected to one of the graph points. Rene Brun { // // To see the output of this macro, click begin_html <a href="gif/graph.gif">here</a>. end_html // gROOT->Reset(); c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500); c1->SetFillColor(42); c1->SetGridx(); c1->SetGridy(); c1->GetFrame()->SetFillColor(21); c1->GetFrame()->SetBorderSize(12); Int_t n = 20; Float_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); printf(" i %i %f %f \n",i,x[i],y[i]); } gr = new TGraph(n,x,y); gr->SetFillColor(19); gr->SetLineColor(2); gr->SetLineWidth(4); gr->SetMarkerColor(4); gr->SetMarkerStyle(21); gr->SetTitle("a simple graph"); gr->Draw("ACP"); //Add axis titles. //A graph is drawn using the services of the TH1F histogram class. //The histogram is created by TGraph::Paint. //TGraph::Paint is called by TCanvas::Update. This function is called by default //when typing <CR> at the keyboard. In a macro, one must force TCanvas::Update. c1->Update(); gr->GetHistogram()->SetXTitle("X title"); gr->GetHistogram()->SetYTitle("Y title"); //Add 1 pad connected to graph point 4 Float_t xpad = c1->GetX2() - c1->GetX1(); Float_t ypad = c1->GetY2() - c1->GetY1(); Float_t x1min = (x[4] - c1->GetX1())/xpad; //convert x[4] to NDC Float_t y1max = (y[4] - c1->GetY1())/ypad; //convert y[4] to NDC Float_t x1max = x1min + 0.2; Float_t y1min = y1max - 0.15; TPad *pad1 = new TPad("p4","pad at point 4",x1min,y1min,x1max,y1max); pad1->Draw(); }
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:28 MET