You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: manual/graphics/index.md
+73-7Lines changed: 73 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,13 +21,13 @@ primitives of any type (graphs, histograms, shapes, tracks, etc.).
21
21
22
22
Adding an element to a pad is done by the `Draw()` method of each class.
23
23
24
-
Painting a pad is done by the `Paint()` method of each object in the list of primitives.
24
+
Painting a pad is done by the automatic call to `Paint()` method of each object in the list of primitives.
25
25
26
26
{% include tutorials name="Graphics" url="graphics" %}
27
27
28
28
## Graphic classes
29
29
30
-
ROOT provides numerous graphic classes, of which the following are among the most used:
30
+
ROOT provides [numerous graphic classes](https://root.cern/doc/master/group__Graphics.html), of which the following are among the most used:
31
31
32
32
- {% include ref class="TCanvas" %}
33
33
@@ -134,6 +134,18 @@ method:
134
134
-_Text and Latex_: Use {% include ref class="TText" %} to draw simple text. {% include ref class="TLatex" %} for complex text like mathematical formulas. Text can be embedded in a box using {% include ref class="TPaveLabel" %}, {% include ref class="TPaveText" %} and {% include ref class="TPavesText" %}.
135
135
- and [_more ..._](https://root.cern/doc/master/group__BasicGraphics.html)
136
136
137
+
138
+
## Colors and color palettes
139
+
140
+
Colors are managed by the class {% include ref class="TColor" %}. A color is defined by its
141
+
RGB or HLS components. It can be accessed via an
142
+
[index](https://root.cern/doc/master/classTColor.html#C00) or
143
+
[by name ](https://root.cern/doc/master/classTColor.html#C02) for the predefined colors.
144
+
Colors can be grouped in [palettes](https://root.cern/doc/master/classTColor.html#C05). More
145
+
than 60 [High quality palettes](https://root.cern/doc/master/classTColor.html#C06) are predefined.
146
+
Color can also be [transparent](https://root.cern/doc/master/classTColor.html#C07).
147
+
148
+
137
149
## Graphical objects attributes and styles
138
150
139
151
There are the following classes for changing the attributes of graphical objects:
@@ -211,7 +223,7 @@ the {% include ref class="TGaxis" %} class.
211
223
_**Example**_
212
224
213
225
{% highlight C++ %}
214
-
TAxis *axis = histo->GetXaxis();
226
+
auto axis = histo->GetXaxis();
215
227
{% endhighlight %}
216
228
217
229
### Setting the axis title
@@ -239,7 +251,7 @@ The axis graphical attributes are managed via the class {% include ref class="TA
239
251
_**Example**_
240
252
241
253
{% highlight C++ %}
242
-
TAxis *axis = histo->GetXaxis();
254
+
auto axis = histo->GetXaxis();
243
255
axis->SetLabelColor(kRed); // change the labels'color to red
244
256
{% endhighlight %}
245
257
@@ -251,10 +263,24 @@ method to set the number of divisions for an axis.
251
263
_**Example**_
252
264
253
265
{% highlight C++ %}
254
-
TAxis *axis = histo->GetXaxis();
266
+
auto axis = histo->GetXaxis();
255
267
axis->SetNdivisions(510); // Set 10 primary divisions and 5 secondary divisions.
256
268
{% endhighlight %}
257
269
270
+
271
+
### Labels tuning
272
+
273
+
Several [axis' attributes can be changed](https://root.cern/doc/master/classTGaxis.html#GA06).
274
+
For instance the [size](https://root.cern/doc/master/classTAttAxis.html#a59684f3441f945f1b2d4e6970ad3d1b5),
275
+
the [distance to the axis](https://root.cern/doc/master/classTAttAxis.html#a73c13dee8312d852b41f2234021e2ffc),
276
+
the [alignment](https://root.cern/doc/master/classTAxis.html#a0abc742bbcfc963863ab3668ce810cc6) etc ...
set the maximum number of digits permitted for the axis labels above which the notation
280
+
with $10^N$ is used.
281
+
282
+
Labels can also be tuning individually thanks to [ChangeLabel()](https://root.cern/doc/master/classTGaxis.html#GA10a).
283
+
258
284
### Setting the axis range
259
285
260
286
- Use [TAxis::SetRange()](https://root.cern/doc/master/classTAxis.html#aed523b084d6b3f24f6b1128d7810e199){:target="_blank"} or [TAxis::SetRangeUser()](https://root.cern/doc/master/classTAxis.html#ac85f8261dedc23bbe68f90afd196cdb8){:target="_blank"} to zoom the axis.
@@ -266,7 +292,7 @@ The `SetRangeUser()` method parameters are user coordinates. If the start or end
266
292
middle of a bin the resulting range is approximation. It finds the low edge bin for the
267
293
start and the high edge bin for the high.
268
294
269
-
For a general description see the ["How to set ranges on axis" FAQ](https://root-forum.cern.ch/t/how-to-set-ranges-on-axis/28254).
295
+
For a general description see the ["How to set ranges on axis" FAQ](https://root-forum.cern/t/how-to-set-ranges-on-axis/28254).
270
296
271
297
### Setting time units for axis
272
298
@@ -433,7 +459,7 @@ A sub-pad is to be built into the active pad (pointed by `gPad`). First, the sub
433
459
build using the {% include ref class="TPad" %} constructor.
434
460
435
461
{% highlight C++ %}
436
-
root [0] spad1 = new TPad("spad1","The first subpad",.1,.1,.5,.5)
462
+
root [0]auto spad1 = new TPad("spad1","The first subpad",.1,.1,.5,.5)
437
463
{% endhighlight %}
438
464
439
465
The NDC (normalized coordinate system) coordinates are specified for the lower left point `(0.1, 0.1)` and for the upper right point `(0.5, 0.5)`.<br>
root [0] gPad->SetLogx(1); // Set the x axis to log in the current pad
632
+
root [1] gPad->SetLogy(0); // Set the y axis to linear in the current pad
633
+
{% endhighlight %}
634
+
635
+
593
636
### Copying a canvas
594
637
595
638
- Use the [TCanvas::DrawClonePad](https://root.cern/doc/master/classTCanvas.html#afcb8727555c9c2be024eb307fd3d295a){:target="_blank"} method to make a copy of the canvas.
596
639
597
640
You can also use the [TObject:DrawClone()](https://root.cern/doc/master/classTObject.html#a7cd0f76ae1791c469f9472a9d4c8d6f9){:target="_blank"} method, to draw a clone of this object in the current selected pad.
598
641
642
+
### Printing a canvas
643
+
644
+
Once a canvas is created and shows plots ready to be included in a publication as a `.png`
645
+
or a `.pdf` image, the [Print()](https://root.cern/doc/master/classTPad.html#ae44fee7e51d69841c1dce4b899eee14d)
646
+
method can be used. All the standard output formats are provided.
647
+
648
+
_**Example**_
649
+
650
+
{% highlight C++ %}
651
+
auto c = new TCanvas(); // Create a canvas
652
+
h->Draw(); // Draw an histogram in the canvas
653
+
c->Print("c1.pdf"); // Save the canvas in a .pdf file
654
+
{% endhighlight %}
655
+
599
656
## Drawing objects with special characters in its name
600
657
601
658
In general, avoid using objects that containing special character like `\`, `/`, `#` etc. in the objects names. Also object names starting with a number might be not accessible from the ROOT command line.
0 commit comments