Yongzhao Zhou wrote: > > Dear Prof. Rene Brun, > Sure, I can change Y scale on a canvas with TGraph by left button of the > mouse using option "ALP" or "AL" to draw a TGraph but in that case the > slider will not be worked. > Is there any function directly to change X scaler of TGraph as action > of TH1 in the macro grSliderAction.C of my code? Because I did not find a > function directly to change the X scaler of a TGraph so I have to use a > TH1 plot and draw a TGraph picture on it to make slider working on TGraph > picture. > Best Regards, > Yongzhao Zhou > > ------ Here is an example with sliders and a TGraph do root > .x gslider.C //------------macro gslider.C { //Example of macro with two sliders TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500); c1->SetFillColor(38); TPad *pad = new TPad("pad","lego pad",0.1,0.1,0.98,0.98); pad->SetFillColor(33); pad->Draw(); pad->cd(); // gStyle->SetFrameFillColor(42); pad->SetFillColor(42); pad->SetGrid(); pad->DrawFrame(0,0,2,11); 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); } gr = new TGraph(n,x,y); gr->SetLineColor(2); gr->SetLineWidth(4); gr->SetMarkerColor(4); gr->SetMarkerStyle(21); gr->SetTitle("a simple graph"); gr->Draw("CP"); //Create two sliders in main canvas. When button1 will be released //the macro xysliderAction.C will be called. c1->cd(); TSlider *xslider = new TSlider("xslider","x",0.1,0.02,0.98,0.08); xslider->SetMethod(".x gsliderAction.C"); TSlider *yslider = new TSlider("yslider","y",0.02,0.1,0.06,0.98); yslider->SetMethod(".x gsliderAction.C"); } //-----------------macro gsliderAction.C { Float_t xrange = 2; Float_t yrange = 11; Float_t xmin = xrange*xslider->GetMinimum(); Float_t xmax = xrange*xslider->GetMaximum(); Float_t ymin = yrange*yslider->GetMinimum(); Float_t ymax = yrange*yslider->GetMaximum(); pad->cd(); pad->DrawFrame(xmin,ymin,xmax,ymax); gr->Draw("cp"); c1->Update(); }
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:28 MET