1.TGraph
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);
}
TGraph *gr1 = new TGraph (n, x, y);
TGraph *gr2 = new TGraph(n);
TGraph *gr3 = new TGraph();
2.绘图选项
The various drawing options for a graph are explained in TGraph::PaintGraph. They are:
• “L” A simple poly-line between every points is drawn 绘制了每个点之间的简单折线
• “F” A fill area is drawn 绘制了一个填充区域
• “F1” Idem as “F” but fill area is no more repartee around X=0 or Y=0
同“F”,但填充区域不再围绕 X=0 或 Y=0
• “F2” draw a fill area poly line connecting the center of bins
绘制连接 bins 中心的填充区域多边形线
• “A” Axis are drawn around the graph 轴绘制在图形周围
• “C” A smooth curve is drawn 绘制出平滑的曲线
• “*” A star is plotted at each point 每个点都绘制了一颗星
• “P” The current marker of the graph is plotted at each point 图形的当前标记绘制在每个点
• “B” A bar chart is drawn at each point 在每个点绘制条形图
• “[]” Only the end vertical/horizontal lines of the error bars are drawn. This option only applies to the TGraphAsymmErrors.
仅绘制误差条的末端垂直/水平线。此选项仅适用于 TGraphAsymmErrors。
• “1” ylow = rwymin
这些选项不区分大小写,并且在大多数情况下它们可以连接起来。
示例:Continuous Line, Axis and Stars (AC*)
void ph(){
Int_t n=20;
Double_t x[n],y[n];
for(Int_t i=0;i<n;i++){
x[i]=0.1*i;
y[i]=10*sin(x[i]+0.2);
}
TGraph *gr1=new TGraph(n,x,y);
TGraph *gr2=new TGraph(n,x,y);
TGraph *gr3=new TGraph(n,x,y);
TCanvas *c1=new TCanvas("c1","Graph Draw Options",200,10,600,400);
gr1->SetFillColor(40);
gr1->Draw("AF");
gr3->SetMarkerStyle(21);
c1->cd(4);
gr3->Draw("APL");
Double_t *nx=gr3->GetX();
Double_t *ny=gr3->GetY();
for(Int_t j=2;j<n-1;j++){
TMarker *m=new TMarker(nx[j],0.5*ny[j],22);
m->SetMarkerSize(2);
m->SetMarkerColor(31+j);
m->Draw();
}
}
3.叠加两张图