Logo ROOT  
Reference Guide
Haxis.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 18/05/95
3
4#include <string.h>
5#include <stdio.h>
6#include <ctype.h>
7
8#include "TH1.h"
9
10
11////////////////////////////////////////////////////////////////////////////////
12/// Choose an axis according to "axis".
13
15{
16 char achoice = toupper(axis[0]);
17 if (achoice == 'X') return 1;
18 if (achoice == 'Y') return 2;
19 if (achoice == 'Z') return 3;
20 return 0;
21}
22
23
24////////////////////////////////////////////////////////////////////////////////
25/// Return the number of divisions for "axis".
26
28{
29 Int_t ax = AxisChoice(axis);
30 if (ax == 1) return fXaxis.GetNdivisions();
31 if (ax == 2) return fYaxis.GetNdivisions();
32 if (ax == 3) return fZaxis.GetNdivisions();
33 return 0;
34}
35
36
37////////////////////////////////////////////////////////////////////////////////
38/// Return the number of divisions for "axis".
39
41{
42 Int_t ax = AxisChoice(axis);
43 if (ax == 1) return fXaxis.GetAxisColor();
44 if (ax == 2) return fYaxis.GetAxisColor();
45 if (ax == 3) return fZaxis.GetAxisColor();
46 return 0;
47}
48
49
50////////////////////////////////////////////////////////////////////////////////
51/// Return the "axis" label color.
52
54{
55 Int_t ax = AxisChoice(axis);
56 if (ax == 1) return fXaxis.GetLabelColor();
57 if (ax == 2) return fYaxis.GetLabelColor();
58 if (ax == 3) return fZaxis.GetLabelColor();
59 return 0;
60}
61
62
63////////////////////////////////////////////////////////////////////////////////
64/// Return the "axis" label font.
65
67{
68 Int_t ax = AxisChoice(axis);
69 if (ax == 1) return fXaxis.GetLabelFont();
70 if (ax == 2) return fYaxis.GetLabelFont();
71 if (ax == 3) return fZaxis.GetLabelFont();
72 return 0;
73}
74
75
76////////////////////////////////////////////////////////////////////////////////
77/// Return the "axis" label offset.
78
80{
81 Int_t ax = AxisChoice(axis);
82 if (ax == 1) return fXaxis.GetLabelOffset();
83 if (ax == 2) return fYaxis.GetLabelOffset();
84 if (ax == 3) return fZaxis.GetLabelOffset();
85 return 0;
86}
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Return the "axis" label size.
91
93{
94 Int_t ax = AxisChoice(axis);
95 if (ax == 1) return fXaxis.GetLabelSize();
96 if (ax == 2) return fYaxis.GetLabelSize();
97 if (ax == 3) return fZaxis.GetLabelSize();
98 return 0;
99}
100
101
102////////////////////////////////////////////////////////////////////////////////
103/// Return the "axis" tick length.
104
106{
107 Int_t ax = AxisChoice(axis);
108 if (ax == 1) return fXaxis.GetTickLength();
109 if (ax == 2) return fYaxis.GetTickLength();
110 if (ax == 3) return fZaxis.GetTickLength();
111 return 0;
112}
113
114
115////////////////////////////////////////////////////////////////////////////////
116/// Return the "axis" title font.
117
119{
120 Int_t ax = AxisChoice(axis);
121 if (ax == 1) return fXaxis.GetTitleFont();
122 if (ax == 2) return fYaxis.GetTitleFont();
123 if (ax == 3) return fZaxis.GetTitleFont();
124 return 0;
125}
126
127
128////////////////////////////////////////////////////////////////////////////////
129/// Return the "axis" title offset.
130
132{
133 Int_t ax = AxisChoice(axis);
134 if (ax == 1) return fXaxis.GetTitleOffset();
135 if (ax == 2) return fYaxis.GetTitleOffset();
136 if (ax == 3) return fZaxis.GetTitleOffset();
137 return 0;
138}
139
140
141////////////////////////////////////////////////////////////////////////////////
142/// Return the "axis" title size.
143
145{
146 Int_t ax = AxisChoice(axis);
147 if (ax == 1) return fXaxis.GetTitleSize();
148 if (ax == 2) return fYaxis.GetTitleSize();
149 if (ax == 3) return fZaxis.GetTitleSize();
150 return 0;
151}
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Set the number of divisions to draw an axis.
156///
157/// ndiv : Number of divisions.
158///
159/// n = N1 + 100*N2 + 10000*N3
160/// N1=number of primary divisions.
161/// N2=number of secondary divisions.
162/// N3=number of 3rd divisions.
163/// e.g.:
164/// nndi=0 --> no tick marks.
165/// nndi=2 --> 2 divisions, one tick mark in the middle
166/// of the axis.
167/// axis specifies which axis ("x","y","z"), default = "x"
168/// if axis="xyz" set all 3 axes
169
171{
172 TString opt = axis;
173 opt.ToLower();
174
175 if (opt.Contains("x")) fXaxis.SetNdivisions(n);
176 if (opt.Contains("y")) fYaxis.SetNdivisions(n);
177 if (opt.Contains("z")) fZaxis.SetNdivisions(n);
178}
179
180
181////////////////////////////////////////////////////////////////////////////////
182/// Set color to draw the axis line and tick marks.
183///
184/// axis specifies which axis ("x","y","z"), default = "x"
185/// if axis="xyz" set all 3 axes
186
188{
189 TString opt = axis;
190 opt.ToLower();
191
192 if (opt.Contains("x")) fXaxis.SetAxisColor(color);
193 if (opt.Contains("y")) fYaxis.SetAxisColor(color);
194 if (opt.Contains("z")) fZaxis.SetAxisColor(color);
195}
196
197
198////////////////////////////////////////////////////////////////////////////////
199/// Set the "axis" range.
200
202{
203 Int_t ax = AxisChoice(axis);
204 TAxis *theAxis = 0;
205 if (ax == 1) theAxis = GetXaxis();
206 if (ax == 2) theAxis = GetYaxis();
207 if (ax == 3) theAxis = GetZaxis();
208 if (!theAxis) return;
209 if (ax > fDimension) {
212 return;
213 }
214 Int_t bin1 = theAxis->FindFixBin(xmin);
215 Int_t bin2 = theAxis->FindFixBin(xmax);
216 theAxis->SetRange(bin1, bin2);
217}
218
219
220////////////////////////////////////////////////////////////////////////////////
221/// Set axis labels color.
222///
223/// axis specifies which axis ("x","y","z"), default = "x"
224/// if axis="xyz" set all 3 axes
225
227{
228 TString opt = axis;
229 opt.ToLower();
230
231 if (opt.Contains("x")) fXaxis.SetLabelColor(color);
232 if (opt.Contains("y")) fYaxis.SetLabelColor(color);
233 if (opt.Contains("z")) fZaxis.SetLabelColor(color);
234}
235
236
237////////////////////////////////////////////////////////////////////////////////
238/// Set font number used to draw axis labels.
239///
240/// font : Text font code = 10*fontnumber + precision
241/// Font numbers must be between 1 and 14
242/// precision = 1 fast hardware fonts (steps in the size)
243/// precision = 2 scalable and rotatable hardware fonts
244///
245/// The default font number is 62.
246/// axis specifies which axis ("x","y","z"), default = "x"
247/// if axis="xyz" set all 3 axes
248
250{
251 TString opt = axis;
252 opt.ToLower();
253
254 if (opt.Contains("x")) fXaxis.SetLabelFont(font);
255 if (opt.Contains("y")) fYaxis.SetLabelFont(font);
256 if (opt.Contains("z")) fZaxis.SetLabelFont(font);
257}
258
259
260////////////////////////////////////////////////////////////////////////////////
261/// Set offset between axis and axis' labels.
262///
263/// The offset is expressed as a percent of the pad height.
264/// axis specifies which axis ("x","y","z"), default = "x"
265/// if axis="xyz" set all 3 axes
266
268{
269 TString opt = axis;
270 opt.ToLower();
271
272 if (opt.Contains("x")) fXaxis.SetLabelOffset(offset);
273 if (opt.Contains("y")) fYaxis.SetLabelOffset(offset);
274 if (opt.Contains("z")) fZaxis.SetLabelOffset(offset);
275}
276
277
278////////////////////////////////////////////////////////////////////////////////
279/// Set size of axis' labels.
280///
281/// The size is expressed as a percent of the pad height.
282/// axis specifies which axis ("x","y","z"), default = "x"
283/// if axis="xyz" set all 3 axes
284
286{
287 TString opt = axis;
288 opt.ToLower();
289
290 if (opt.Contains("x")) fXaxis.SetLabelSize(size);
291 if (opt.Contains("y")) fYaxis.SetLabelSize(size);
292 if (opt.Contains("z")) fZaxis.SetLabelSize(size);
293}
294
295
296////////////////////////////////////////////////////////////////////////////////
297/// Set the axis' tick marks length.
298///
299/// axis specifies which axis ("x","y","z"), default = "x"
300/// if axis="xyz" set all 3 axes
301
303{
304 TString opt = axis;
305 opt.ToLower();
306
307 if (opt.Contains("x")) fXaxis.SetTickLength(length);
308 if (opt.Contains("y")) fYaxis.SetTickLength(length);
309 if (opt.Contains("z")) fZaxis.SetTickLength(length);
310}
311
312
313////////////////////////////////////////////////////////////////////////////////
314/// Set the axis' title font.
315///
316/// - if axis =="x" set the X axis title font
317/// - if axis =="y" set the Y axis title font
318/// - if axis =="z" set the Z axis title font
319/// any other value of axis will set the pad title font
320///
321/// if axis="xyz" set all 3 axes
322
324{
325 TString opt = axis;
326 opt.ToLower();
327
328 if (opt.Contains("x")) fXaxis.SetTitleFont(font);
329 if (opt.Contains("y")) fYaxis.SetTitleFont(font);
330 if (opt.Contains("z")) fZaxis.SetTitleFont(font);
331}
332
333
334////////////////////////////////////////////////////////////////////////////////
335/// Specify a parameter offset to control the distance between the axis
336/// and the axis' title.
337///
338/// - offset = 1 means : use the default distance
339/// - offset = 1.2 means: the distance will be 1.2*(default distance)
340/// - offset = 0.8 means: the distance will be 0.8*(default distance)
341///
342/// axis specifies which axis ("x","y","z"), default = "x"
343/// if axis="xyz" set all 3 axes
344
346{
347 TString opt = axis;
348 opt.ToLower();
349
350 if (opt.Contains("x")) fXaxis.SetTitleOffset(offset);
351 if (opt.Contains("y")) fYaxis.SetTitleOffset(offset);
352 if (opt.Contains("z")) fZaxis.SetTitleOffset(offset);
353}
354
355
356////////////////////////////////////////////////////////////////////////////////
357/// Set the axis' title size.
358///
359/// - if axis = "x" set the X axis title size
360/// - if axis = "y" set the Y axis title size
361/// - if axis = "z" set the Z axis title size
362///
363/// if axis ="xyz" set all 3 axes
364
366{
367 TString opt = axis;
368 opt.ToLower();
369
370 if (opt.Contains("x")) fXaxis.SetTitleSize(size);
371 if (opt.Contains("y")) fYaxis.SetTitleSize(size);
372 if (opt.Contains("z")) fZaxis.SetTitleSize(size);
373}
double Axis_t
Definition: RtypesCore.h:74
short Color_t
Definition: RtypesCore.h:81
short Style_t
Definition: RtypesCore.h:78
float Float_t
Definition: RtypesCore.h:55
const char Option_t
Definition: RtypesCore.h:64
float xmin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
virtual Color_t GetLabelColor() const
Definition: TAttAxis.h:38
virtual Int_t GetNdivisions() const
Definition: TAttAxis.h:36
virtual Color_t GetAxisColor() const
Definition: TAttAxis.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:294
virtual Style_t GetTitleFont() const
Definition: TAttAxis.h:47
virtual Float_t GetLabelOffset() const
Definition: TAttAxis.h:40
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
Set color of the line axis and tick marks.
Definition: TAttAxis.cxx:163
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition: TAttAxis.cxx:204
virtual Style_t GetLabelFont() const
Definition: TAttAxis.h:39
virtual void SetTitleFont(Style_t font=62)
Set the title font.
Definition: TAttAxis.cxx:322
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition: TAttAxis.cxx:193
virtual void SetLabelFont(Style_t font=62)
Set labels' font.
Definition: TAttAxis.cxx:183
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title.
Definition: TAttAxis.cxx:304
virtual Float_t GetTitleSize() const
Definition: TAttAxis.h:44
virtual Float_t GetLabelSize() const
Definition: TAttAxis.h:41
virtual Float_t GetTickLength() const
Definition: TAttAxis.h:45
virtual Float_t GetTitleOffset() const
Definition: TAttAxis.h:43
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length.
Definition: TAttAxis.cxx:280
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:229
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
Set color of labels.
Definition: TAttAxis.cxx:173
Class to manage histogram axis.
Definition: TAxis.h:30
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:416
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis from bin first to last.
Definition: TAxis.cxx:914
virtual void SetLabelFont(Style_t font=62, Option_t *axis="X")
Set font number used to draw axis labels.
Definition: Haxis.cxx:249
virtual Color_t GetLabelColor(Option_t *axis="X") const
Return the "axis" label color.
Definition: Haxis.cxx:53
virtual void SetTitleSize(Float_t size=0.02, Option_t *axis="X")
Set the axis' title size.
Definition: Haxis.cxx:365
TAxis * GetZaxis()
Definition: TH1.h:318
virtual void SetLabelOffset(Float_t offset=0.005, Option_t *axis="X")
Set offset between axis and axis' labels.
Definition: Haxis.cxx:267
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:316
virtual Style_t GetTitleFont(Option_t *axis="X") const
Return the "axis" title font.
Definition: Haxis.cxx:118
virtual void SetNdivisions(Int_t n=510, Option_t *axis="X")
Set the number of divisions to draw an axis.
Definition: Haxis.cxx:170
virtual Style_t GetLabelFont(Option_t *axis="X") const
Return the "axis" label font.
Definition: Haxis.cxx:66
virtual Float_t GetTickLength(Option_t *axis="X") const
Return the "axis" tick length.
Definition: Haxis.cxx:105
virtual Float_t GetTitleSize(Option_t *axis="X") const
Return the "axis" title size.
Definition: Haxis.cxx:144
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:394
Int_t fDimension
!Histogram dimension (1, 2 or 3 dim)
Definition: TH1.h:107
TAxis * GetYaxis()
Definition: TH1.h:317
virtual Float_t GetLabelSize(Option_t *axis="X") const
Return the "axis" label size.
Definition: Haxis.cxx:92
virtual Int_t GetNdivisions(Option_t *axis="X") const
Return the number of divisions for "axis".
Definition: Haxis.cxx:27
Int_t AxisChoice(Option_t *axis) const
Choose an axis according to "axis".
Definition: Haxis.cxx:14
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
virtual Float_t GetTitleOffset(Option_t *axis="X") const
Return the "axis" title offset.
Definition: Haxis.cxx:131
TAxis fZaxis
Z axis descriptor.
Definition: TH1.h:89
virtual Float_t GetLabelOffset(Option_t *axis="X") const
Return the "axis" label offset.
Definition: Haxis.cxx:79
TAxis fXaxis
X axis descriptor.
Definition: TH1.h:87
virtual void SetTitleOffset(Float_t offset=1, Option_t *axis="X")
Specify a parameter offset to control the distance between the axis and the axis' title.
Definition: Haxis.cxx:345
virtual void SetLabelColor(Color_t color=1, Option_t *axis="X")
Set axis labels color.
Definition: Haxis.cxx:226
virtual void SetAxisColor(Color_t color=1, Option_t *axis="X")
Set color to draw the axis line and tick marks.
Definition: Haxis.cxx:187
virtual void SetAxisRange(Double_t xmin, Double_t xmax, Option_t *axis="X")
Set the "axis" range.
Definition: Haxis.cxx:201
virtual void SetTitleFont(Style_t font=62, Option_t *axis="X")
Set the axis' title font.
Definition: Haxis.cxx:323
virtual Color_t GetAxisColor(Option_t *axis="X") const
Return the number of divisions for "axis".
Definition: Haxis.cxx:40
TAxis fYaxis
Y axis descriptor.
Definition: TH1.h:88
virtual void SetLabelSize(Float_t size=0.02, Option_t *axis="X")
Set size of axis' labels.
Definition: Haxis.cxx:285
virtual void SetTickLength(Float_t length=0.02, Option_t *axis="X")
Set the axis' tick marks length.
Definition: Haxis.cxx:302
Basic string class.
Definition: TString.h:131
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
const Int_t n
Definition: legend1.C:16