Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
gr202_textmarkers.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Draw a graph with text attached to each point.

The text is drawn in a TExec function attached to the TGraph, therefore if the a graph's point is moved interactively, the text will be automatically updated.

void gr202_textmarkers() {
TCanvas *c = new TCanvas("c","A Simple Graph Example with Text",700,500);
c->SetGrid();
const Int_t n = 10;
auto gr = new TGraph(n);
gr->SetTitle("A Simple Graph Example with Text");
gr->SetMarkerStyle(20);
auto ex = new TExec("ex","drawtext();");
gr->GetListOfFunctions()->Add(ex);
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;
l.SetTextSize(0.025);
l.SetTextFont(42);
l.SetTextAlign(21);
l.SetTextColor(kBlue);
auto g = (TGraph*)gPad->GetListOfPrimitives()->FindObject("Graph");
n = g->GetN();
for (i=0; i<n; i++) {
g->GetPoint(i,x,y);
l.PaintText(x,y+0.2,Form("(%4.2f,%4.2f)",x,y));
}
}
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
@ kBlue
Definition Rtypes.h:67
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2496
#define gPad
The Canvas class.
Definition TCanvas.h:23
TExec is a utility class that can be used to execute a C++ command when some event happens in a pad.
Definition TExec.h:26
void drawtext(double x, double y, int f, const char *s)
Definition fonts.C:1
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25
Double_t ex[n]
Definition legend1.C:17
TLine l
Definition textangle.C:4
Author
Olivier Couet

Definition in file gr202_textmarkers.C.