ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 /// ndiv : Number of divisions.
157 ///
158 /// n = N1 + 100*N2 + 10000*N3
159 /// N1=number of primary divisions.
160 /// N2=number of secondary divisions.
161 /// N3=number of 3rd divisions.
162 /// e.g.:
163 /// nndi=0 --> no tick marks.
164 /// nndi=2 --> 2 divisions, one tick mark in the middle
165 /// of the axis.
166 /// axis specifies which axis ("x","y","z"), default = "x"
167 /// if axis="xyz" set all 3 axes
168 
170 {
171  TString opt = axis;
172  opt.ToLower();
173 
174  if (opt.Contains("x")) fXaxis.SetNdivisions(n);
175  if (opt.Contains("y")) fYaxis.SetNdivisions(n);
176  if (opt.Contains("z")) fZaxis.SetNdivisions(n);
177 }
178 
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Set color to draw the axis line and tick marks.
182 /// axis specifies which axis ("x","y","z"), default = "x"
183 /// if axis="xyz" set all 3 axes
184 
186 {
187  TString opt = axis;
188  opt.ToLower();
189 
190  if (opt.Contains("x")) fXaxis.SetAxisColor(color);
191  if (opt.Contains("y")) fYaxis.SetAxisColor(color);
192  if (opt.Contains("z")) fZaxis.SetAxisColor(color);
193 }
194 
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Set the "axis" range.
198 
200 {
201  Int_t ax = AxisChoice(axis);
202  TAxis *theAxis = 0;
203  if (ax == 1) theAxis = GetXaxis();
204  if (ax == 2) theAxis = GetYaxis();
205  if (ax == 3) theAxis = GetZaxis();
206  if (!theAxis) return;
207  if (ax > fDimension) {
208  SetMinimum(xmin);
209  SetMaximum(xmax);
210  return;
211  }
212  Int_t bin1 = theAxis->FindFixBin(xmin);
213  Int_t bin2 = theAxis->FindFixBin(xmax);
214  theAxis->SetRange(bin1, bin2);
215 }
216 
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Set axis labels color.
220 /// axis specifies which axis ("x","y","z"), default = "x"
221 /// if axis="xyz" set all 3 axes
222 
224 {
225  TString opt = axis;
226  opt.ToLower();
227 
228  if (opt.Contains("x")) fXaxis.SetLabelColor(color);
229  if (opt.Contains("y")) fYaxis.SetLabelColor(color);
230  if (opt.Contains("z")) fZaxis.SetLabelColor(color);
231 }
232 
233 
234 ////////////////////////////////////////////////////////////////////////////////
235 /// Set font number used to draw axis labels.
236 /// font : Text font code = 10*fontnumber + precision
237 /// Font numbers must be between 1 and 14
238 /// precision = 1 fast hardware fonts (steps in the size)
239 /// precision = 2 scalable and rotatable hardware fonts
240 /// The default font number is 62.
241 /// axis specifies which axis ("x","y","z"), default = "x"
242 /// if axis="xyz" set all 3 axes
243 
245 {
246  TString opt = axis;
247  opt.ToLower();
248 
249  if (opt.Contains("x")) fXaxis.SetLabelFont(font);
250  if (opt.Contains("y")) fYaxis.SetLabelFont(font);
251  if (opt.Contains("z")) fZaxis.SetLabelFont(font);
252 }
253 
254 
255 ////////////////////////////////////////////////////////////////////////////////
256 /// Set offset between axis and axis' labels.
257 /// The offset is expressed as a percent of the pad height.
258 /// axis specifies which axis ("x","y","z"), default = "x"
259 /// if axis="xyz" set all 3 axes
260 
262 {
263  TString opt = axis;
264  opt.ToLower();
265 
266  if (opt.Contains("x")) fXaxis.SetLabelOffset(offset);
267  if (opt.Contains("y")) fYaxis.SetLabelOffset(offset);
268  if (opt.Contains("z")) fZaxis.SetLabelOffset(offset);
269 }
270 
271 
272 ////////////////////////////////////////////////////////////////////////////////
273 /// Set size of axis' labels.
274 /// The size is expressed as a percent of the pad height.
275 /// axis specifies which axis ("x","y","z"), default = "x"
276 /// if axis="xyz" set all 3 axes
277 
279 {
280  TString opt = axis;
281  opt.ToLower();
282 
283  if (opt.Contains("x")) fXaxis.SetLabelSize(size);
284  if (opt.Contains("y")) fYaxis.SetLabelSize(size);
285  if (opt.Contains("z")) fZaxis.SetLabelSize(size);
286 }
287 
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 /// Set the axis' tick marks length.
291 /// axis specifies which axis ("x","y","z"), default = "x"
292 /// if axis="xyz" set all 3 axes
293 
295 {
296  TString opt = axis;
297  opt.ToLower();
298 
299  if (opt.Contains("x")) fXaxis.SetTickLength(length);
300  if (opt.Contains("y")) fYaxis.SetTickLength(length);
301  if (opt.Contains("z")) fZaxis.SetTickLength(length);
302 }
303 
304 
305 ////////////////////////////////////////////////////////////////////////////////
306 /// The the axis' title font.
307 /// if axis =="x" set the X axis title font
308 /// if axis =="y" set the Y axis title font
309 /// if axis =="z" set the Z axis title font
310 /// any other value of axis will set the pad title font
311 ///
312 /// if axis="xyz" set all 3 axes
313 
315 {
316  TString opt = axis;
317  opt.ToLower();
318 
319  if (opt.Contains("x")) fXaxis.SetTitleFont(font);
320  if (opt.Contains("y")) fYaxis.SetTitleFont(font);
321  if (opt.Contains("z")) fZaxis.SetTitleFont(font);
322 }
323 
324 
325 ////////////////////////////////////////////////////////////////////////////////
326 /// Specify a parameter offset to control the distance between the axis
327 /// and the axis' title.
328 /// offset = 1 means : use the default distance
329 /// offset = 1.2 means: the distance will be 1.2*(default distance)
330 /// offset = 0.8 means: the distance will be 0.8*(default distance)
331 ///
332 /// axis specifies which axis ("x","y","z"), default = "x"
333 /// if axis="xyz" set all 3 axes
334 
336 {
337  TString opt = axis;
338  opt.ToLower();
339 
340  if (opt.Contains("x")) fXaxis.SetTitleOffset(offset);
341  if (opt.Contains("y")) fYaxis.SetTitleOffset(offset);
342  if (opt.Contains("z")) fZaxis.SetTitleOffset(offset);
343 }
344 
345 
346 ////////////////////////////////////////////////////////////////////////////////
347 /// The the axis' title size.
348 /// if axis = "x" set the X axis title size
349 /// if axis = "y" set the Y axis title size
350 /// if axis = "z" set the Z axis title size
351 ///
352 /// if axis ="xyz" set all 3 axes
353 
355 {
356  TString opt = axis;
357  opt.ToLower();
358 
359  if (opt.Contains("x")) fXaxis.SetTitleSize(size);
360  if (opt.Contains("y")) fYaxis.SetTitleSize(size);
361  if (opt.Contains("z")) fZaxis.SetTitleSize(size);
362 }
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:245
virtual Color_t GetAxisColor() const
Definition: TAttAxis.h:51
float xmin
Definition: THbookFile.cxx:93
virtual Float_t GetTickLength(Option_t *axis="X") const
Return the "axis" tick length.
Definition: Haxis.cxx:105
virtual Color_t GetLabelColor() const
Definition: TAttAxis.h:52
virtual void SetTitleFont(Style_t font=62, Option_t *axis="X")
The the axis' title font.
Definition: Haxis.cxx:314
Int_t AxisChoice(Option_t *axis) const
Choose an axis according to "axis".
Definition: Haxis.cxx:14
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:394
short Style_t
Definition: RtypesCore.h:76
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
tuple offset
Definition: tree.py:93
double Axis_t
Definition: RtypesCore.h:72
TAxis fYaxis
Definition: TH1.h:103
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
Set color of labels.
Definition: TAttAxis.cxx:156
virtual void SetNdivisions(Int_t n=510, Option_t *axis="X")
Set the number of divisions to draw an axis.
Definition: Haxis.cxx:169
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:212
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
virtual void SetLabelSize(Float_t size=0.02, Option_t *axis="X")
Set size of axis' labels.
Definition: Haxis.cxx:278
Basic string class.
Definition: TString.h:137
virtual Float_t GetLabelOffset(Option_t *axis="X") const
Return the "axis" label offset.
Definition: Haxis.cxx:79
virtual Color_t GetAxisColor(Option_t *axis="X") const
Return the number of divisions for "axis".
Definition: Haxis.cxx:40
virtual void SetTitleFont(Style_t font=62)
Set the title font.
Definition: TAttAxis.cxx:273
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1075
int Int_t
Definition: RtypesCore.h:41
virtual Style_t GetTitleFont() const
Definition: TAttAxis.h:60
virtual Float_t GetLabelSize(Option_t *axis="X") const
Return the "axis" label size.
Definition: Haxis.cxx:92
virtual void SetAxisRange(Double_t xmin, Double_t xmax, Option_t *axis="X")
Set the "axis" range.
Definition: Haxis.cxx:199
TAxis fZaxis
Definition: TH1.h:104
virtual Float_t GetTitleSize() const
Definition: TAttAxis.h:57
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels The distance is expressed in per cent of the pad width...
Definition: TAttAxis.cxx:176
virtual void SetLabelFont(Style_t font=62)
Set labels' font.
Definition: TAttAxis.cxx:166
virtual void SetLabelFont(Style_t font=62, Option_t *axis="X")
Set font number used to draw axis labels.
Definition: Haxis.cxx:244
virtual Float_t GetTitleOffset() const
Definition: TAttAxis.h:56
short Color_t
Definition: RtypesCore.h:79
virtual void SetAxisColor(Color_t color=1, Option_t *axis="X")
Set color to draw the axis line and tick marks.
Definition: Haxis.cxx:185
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:831
virtual Int_t GetNdivisions(Option_t *axis="X") const
Return the number of divisions for "axis".
Definition: Haxis.cxx:27
Double_t length(const TVector2 &v)
Definition: CsgOps.cxx:347
Class to manage histogram axis.
Definition: TAxis.h:36
TAxis * GetYaxis()
Definition: TH1.h:320
float xmax
Definition: THbookFile.cxx:93
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
Set color of the line axis and tick marks.
Definition: TAttAxis.cxx:146
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:187
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:255
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")
The the axis' title size.
Definition: Haxis.cxx:354
virtual Style_t GetLabelFont() const
Definition: TAttAxis.h:53
virtual Int_t GetNdivisions() const
Definition: TAttAxis.h:50
TAxis * GetZaxis()
Definition: TH1.h:321
virtual void SetTickLength(Float_t length=0.02, Option_t *axis="X")
Set the axis' tick marks length.
Definition: Haxis.cxx:294
virtual Float_t GetLabelSize() const
Definition: TAttAxis.h:55
Bool_t axis
Definition: geodemo.C:37
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:390
virtual Float_t GetTitleSize(Option_t *axis="X") const
Return the "axis" title size.
Definition: Haxis.cxx:144
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
Int_t fDimension
Pointer to directory holding this histogram.
Definition: TH1.h:122
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length The length is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:232
TAxis fXaxis
Definition: TH1.h:102
virtual Style_t GetLabelFont(Option_t *axis="X") const
Return the "axis" label font.
Definition: Haxis.cxx:66
virtual Style_t GetTitleFont(Option_t *axis="X") const
Return the "axis" title font.
Definition: Haxis.cxx:118
virtual Float_t GetTickLength() const
Definition: TAttAxis.h:58
const Int_t n
Definition: legend1.C:16
TAxis * GetXaxis()
Definition: TH1.h:319
virtual Float_t GetTitleOffset(Option_t *axis="X") const
Return the "axis" title offset.
Definition: Haxis.cxx:131
virtual void SetLabelColor(Color_t color=1, Option_t *axis="X")
Set axis labels color.
Definition: Haxis.cxx:223
virtual void SetLabelOffset(Float_t offset=0.005, Option_t *axis="X")
Set offset between axis and axis' labels.
Definition: Haxis.cxx:261
virtual Float_t GetLabelOffset() const
Definition: TAttAxis.h:54
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:335