| 51 |
<a href="http://root.cern.ch/root/html/TGraphPainter.html">TGraphPainter</a> |
<a href="http://root.cern.ch/root/html/TGraphPainter.html">TGraphPainter</a> |
| 52 |
class. All details about the various painting options are given in |
class. All details about the various painting options are given in |
| 53 |
<a href="http://root.cern.ch/root/html/TGraphPainter.html">this class</a>. |
<a href="http://root.cern.ch/root/html/TGraphPainter.html">this class</a>. |
|
<p> |
|
| 54 |
Example: |
Example: |
| 55 |
<pre> |
<pre> |
| 56 |
TGraph *gr1 = new TGraph(... |
TGraph *gr1 = new TGraph(... |
| 60 |
mg->Add(gr2,"cp"); |
mg->Add(gr2,"cp"); |
| 61 |
mg->Draw("a"); |
mg->Draw("a"); |
| 62 |
</pre> |
</pre> |
| 63 |
<br> |
<p> |
| 64 |
|
The number of graphs in a multigraph can be retrieve with: |
| 65 |
|
<pre> |
| 66 |
|
mg->GetListOfGraphs()->GetSize(); |
| 67 |
|
</pre> |
| 68 |
|
<p> |
| 69 |
The drawing option for each TGraph may be specified as an optional |
The drawing option for each TGraph may be specified as an optional |
| 70 |
second argument of the <tt>Add</tt> function. |
second argument of the <tt>Add</tt> function. |
| 71 |
<p> |
<p> |
| 121 |
mg->Add(g2); |
mg->Add(g2); |
| 122 |
mg->Draw("apl"); |
mg->Draw("apl"); |
| 123 |
</pre> |
</pre> |
| 124 |
|
<p> |
| 125 |
|
When the graphs in a TMultiGraph are fitted, the fit parameters boxes |
| 126 |
|
overlap. The following example shows how to make them all visible. |
| 127 |
|
|
| 128 |
|
End_Html |
| 129 |
|
Begin_Macro(source) |
| 130 |
|
../../../tutorials/graphs/multigraph.C |
| 131 |
|
End_Macro |
| 132 |
|
Begin_Html |
| 133 |
|
|
| 134 |
|
<p> |
| 135 |
|
The axis limits can be changed the like for TGraph. The same methods apply on |
| 136 |
|
the multigraph. |
| 137 |
|
Note the two differents ways to change limits on X and Y axis. |
| 138 |
|
|
| 139 |
|
End_Html |
| 140 |
|
Begin_Macro(source) |
| 141 |
|
{ |
| 142 |
|
TCanvas *c2 = new TCanvas("c2","c2",600,400); |
| 143 |
|
|
| 144 |
|
TGraph *g[3]; |
| 145 |
|
Double_t x[10] = {0,1,2,3,4,5,6,7,8,9}; |
| 146 |
|
Double_t y[10] = {1,2,3,4,5,5,4,3,2,1}; |
| 147 |
|
TMultiGraph *mg = new TMultiGraph(); |
| 148 |
|
for (int i=0; i<3; i++) { |
| 149 |
|
g[i] = new TGraph(10, x, y); |
| 150 |
|
g[i]->SetMarkerStyle(20); |
| 151 |
|
g[i]->SetMarkerColor(i+2); |
| 152 |
|
for (int j=0; j<10; j++) y[j] = y[j]-1; |
| 153 |
|
mg->Add(g[i]); |
| 154 |
|
} |
| 155 |
|
mg->Draw("APL"); |
| 156 |
|
mg->GetXaxis()->SetTitle("E_{#gamma} (GeV)"); |
| 157 |
|
mg->GetYaxis()->SetTitle("Coefficients"); |
| 158 |
|
|
| 159 |
|
// Change the axis limits |
| 160 |
|
gPad->Modified(); |
| 161 |
|
mg->GetXaxis()->SetLimits(1.5,7.5); |
| 162 |
|
mg->SetMinimum(0.); |
| 163 |
|
mg->SetMaximum(10.); |
| 164 |
|
|
| 165 |
|
return c2; |
| 166 |
|
} |
| 167 |
|
End_Macro |
| 168 |
|
Begin_Html |
| 169 |
|
<p> |
| 170 |
|
The method <a href="http://root.cern.ch/root/html/TPad.html#TPad:BuildLegend"> |
| 171 |
|
<tt>TPad::BuildLegend</tt></a> is able to extract the graphs inside a |
| 172 |
|
multigraph. The following example demonstrate this. |
| 173 |
|
|
| 174 |
|
End_Html |
| 175 |
|
Begin_Macro(source) |
| 176 |
|
{ |
| 177 |
|
TCanvas *c3 = new TCanvas("c3","c3",600, 400); |
| 178 |
|
|
| 179 |
|
TMultiGraph * mg = new TMultiGraph("mg","mg"); |
| 180 |
|
|
| 181 |
|
const Int_t size = 10; |
| 182 |
|
|
| 183 |
|
double x[size]; |
| 184 |
|
double y1[size]; |
| 185 |
|
double y2[size]; |
| 186 |
|
double y3[size]; |
| 187 |
|
|
| 188 |
|
for ( int i = 0; i < size ; ++i ) { |
| 189 |
|
x[i] = i; |
| 190 |
|
y1[i] = size - i; |
| 191 |
|
y2[i] = size - 0.5 * i; |
| 192 |
|
y3[i] = size - 0.6 * i; |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
TGraph * gr1 = new TGraph( size, x, y1 ); |
| 196 |
|
gr1->SetName("gr1"); |
| 197 |
|
gr1->SetTitle("graph 1"); |
| 198 |
|
gr1->SetMarkerStyle(21); |
| 199 |
|
gr1->SetDrawOption("AP"); |
| 200 |
|
gr1->SetLineColor(2); |
| 201 |
|
gr1->SetLineWidth(4); |
| 202 |
|
gr1->SetFillStyle(0); |
| 203 |
|
|
| 204 |
|
TGraph * gr2 = new TGraph( size, x, y2 ); |
| 205 |
|
gr2->SetName("gr2"); |
| 206 |
|
gr2->SetTitle("graph 2"); |
| 207 |
|
gr2->SetMarkerStyle(22); |
| 208 |
|
gr2->SetMarkerColor(2); |
| 209 |
|
gr2->SetDrawOption("P"); |
| 210 |
|
gr2->SetLineColor(3); |
| 211 |
|
gr2->SetLineWidth(4); |
| 212 |
|
gr2->SetFillStyle(0); |
| 213 |
|
|
| 214 |
|
TGraph * gr3 = new TGraph( size, x, y3 ); |
| 215 |
|
gr3->SetName("gr3"); |
| 216 |
|
gr3->SetTitle("graph 3"); |
| 217 |
|
gr3->SetMarkerStyle(23); |
| 218 |
|
gr3->SetLineColor(4); |
| 219 |
|
gr3->SetLineWidth(4); |
| 220 |
|
gr3->SetFillStyle(0); |
| 221 |
|
|
| 222 |
|
mg->Add( gr1 ); |
| 223 |
|
mg->Add( gr2 ); |
| 224 |
|
|
| 225 |
|
gr3->Draw("ALP"); |
| 226 |
|
mg->Draw("LP"); |
| 227 |
|
c3->BuildLegend(); |
| 228 |
|
|
| 229 |
|
return c3; |
| 230 |
|
} |
| 231 |
|
End_Macro |
| 232 |
|
Begin_Html |
| 233 |
|
|
| 234 |
|
|
| 235 |
End_Html */ |
End_Html */ |
| 236 |
|
|