graphstruct.C: Draw a simple graph structure. | TGraph, TGraphErrors, etc | gtime.C: example of TGraphTime |
// Draw a graph with text attached to each point. // The text is drawn in a TExec function, therefore if the text is // moved interactively, it will be automatically updated. // Author: Olivier Couet void graphtext() { TCanvas *c = new TCanvas("c","A Simple Graph Example with Text",700,500); c->SetGrid(); const Int_t n = 10; TGraph *gr = new TGraph(n); gr->SetTitle("A Simple Graph Example with Text"); gr->SetMarkerStyle(20); TExec *ex = new TExec("ex","drawtext();"); gr->GetListOfFunctions()->Add(ex); Double_t x, y; for (Int_t i=0;i<n;i++) { x = i*0.1; y = 10*sin(x+0.2); gr->SetPoint(i,x,y); } gr->Draw("ALP"); } void drawtext() { Int_t i,n; Double_t x,y; TLatex *l; TGraph *g = (TGraph*)gPad->GetListOfPrimitives()->FindObject("Graph"); n = g->GetN(); for (i=1; i<n; i++) { g->GetPoint(i,x,y); l = new TLatex(x,y+0.2,Form("%4.2f",y)); l->SetTextSize(0.025); l->SetTextFont(42); l->SetTextAlign(21); l->Paint(); } } graphtext.C:1 graphtext.C:2 graphtext.C:3 graphtext.C:4 graphtext.C:5 graphtext.C:6 graphtext.C:7 graphtext.C:8 graphtext.C:9 graphtext.C:10 graphtext.C:11 graphtext.C:12 graphtext.C:13 graphtext.C:14 graphtext.C:15 graphtext.C:16 graphtext.C:17 graphtext.C:18 graphtext.C:19 graphtext.C:20 graphtext.C:21 graphtext.C:22 graphtext.C:23 graphtext.C:24 graphtext.C:25 graphtext.C:26 graphtext.C:27 graphtext.C:28 graphtext.C:29 graphtext.C:30 graphtext.C:31 graphtext.C:32 graphtext.C:33 graphtext.C:34 graphtext.C:35 graphtext.C:36 graphtext.C:37 graphtext.C:38 graphtext.C:39 graphtext.C:40 graphtext.C:41 graphtext.C:42 graphtext.C:43 graphtext.C:44 |
|