Logo ROOT  
Reference Guide
TAxis.h
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: Rene Brun 12/12/94
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TAxis
13 #define ROOT_TAxis
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TAxis //
19 // //
20 // Axis class. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TNamed.h"
25 #include "TAttAxis.h"
26 #include "TArrayD.h"
27 
28 class THashList;
29 
30 class TAxis : public TNamed, public TAttAxis {
31 
32 private:
33  Int_t fNbins; //Number of bins
34  Double_t fXmin; //low edge of first bin
35  Double_t fXmax; //upper edge of last bin
36  TArrayD fXbins; //Bin edges array in X
37  Int_t fFirst; //first bin to display
38  Int_t fLast; //last bin to display
39  UShort_t fBits2; //second bit status word
40  Bool_t fTimeDisplay; //on/off displaying time values instead of numerics
41  TString fTimeFormat; //Date&time format, ex: 09/12/99 12:34:00
42  TObject *fParent; //!Object owning this axis
43  THashList *fLabels; //List of labels
44  TList *fModLabs; //List of modified labels
45 
46  // TAxis extra status bits (stored in fBits2)
47  enum {
48  kAlphanumeric = BIT(0), // axis is alphanumeric
49  kCanExtend = BIT(1), // axis can be extended
50  kNotAlpha = BIT(2) // axis is forced to be not alphanumeric
51  };
52 
53  Bool_t HasBinWithoutLabel() const;
54 
55 public:
56  // TAxis status bits
57  enum EStatusBits {
58  kDecimals = BIT(7),
59  kTickPlus = BIT(9),
60  kTickMinus = BIT(10),
61  kAxisRange = BIT(11),
63  kCenterLabels = BIT(14), //bit 13 is used by TObject
65  kPalette = BIT(16),
70  kLabelsUp = BIT(21),
71  kIsInteger = BIT(22),
73  };
74 
75  TAxis();
77  TAxis(Int_t nbins, const Double_t *xbins);
78  TAxis(const TAxis &axis);
79  virtual ~TAxis();
80  TAxis& operator=(const TAxis&);
81 
82  Bool_t CanExtend() const { return (fBits2 & kCanExtend); }
85  void SetAlphanumeric(Bool_t alphanumeric = kTRUE);
86  void SetCanExtend(Bool_t canExtend) { fBits2 = canExtend ? (fBits2 | kCanExtend) : (fBits2 & ~kCanExtend); }
87  void SetNoAlphanumeric(Bool_t noalpha = kTRUE) {
88  fBits2 = noalpha ? (fBits2 | kNotAlpha) : (fBits2 & ~kNotAlpha);
89  if (IsAlphanumeric() ) {
92  }
93  }
94  void CenterLabels(Bool_t center=kTRUE);
95  void CenterTitle(Bool_t center=kTRUE);
96  const char *ChooseTimeFormat(Double_t axislength=0);
97  virtual void Copy(TObject &axis) const;
98  virtual void Delete(Option_t * /*option*/ ="") { }
99  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
100  virtual TObject *DrawClone(Option_t * /*option*/ ="") const {return 0;}
101  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
102  virtual Int_t FindBin(Double_t x);
103  virtual Int_t FindBin(Double_t x) const { return FindFixBin(x); }
104  virtual Int_t FindBin(const char *label);
105  virtual Int_t FindFixBin(Double_t x) const;
106  virtual Int_t FindFixBin(const char *label) const;
107  virtual Double_t GetBinCenter(Int_t bin) const;
108  virtual Double_t GetBinCenterLog(Int_t bin) const;
109  const char *GetBinLabel(Int_t bin) const;
110  virtual Double_t GetBinLowEdge(Int_t bin) const;
111  virtual Double_t GetBinUpEdge(Int_t bin) const;
112  virtual Double_t GetBinWidth(Int_t bin) const;
113  virtual void GetCenter(Double_t *center) const;
116  Bool_t GetDecimals() const { return TestBit(kDecimals); }
117  THashList *GetLabels() const { return fLabels; }
118  TList *GetModifiedLabels() const { return fModLabs; }
119  virtual void GetLowEdge(Double_t *edge) const;
121  Int_t GetNbins() const { return fNbins; }
123  virtual TObject *GetParent() const {return fParent;}
125  virtual const char *GetTicks() const;
126  virtual Bool_t GetTimeDisplay() const {return fTimeDisplay;}
127  virtual const char *GetTimeFormat() const {return fTimeFormat.Data();}
128  virtual const char *GetTimeFormatOnly() const;
129  const char *GetTitle() const {return fTitle.Data();}
130  const TArrayD *GetXbins() const {return &fXbins;}
131  Int_t GetFirst() const;
132  Int_t GetLast() const;
133  Double_t GetXmin() const {return fXmin;}
134  Double_t GetXmax() const {return fXmax;}
135  virtual void ImportAttributes(const TAxis *axis);
137  // true if axis has variable bin sizes, false otherwise
138  return (fXbins.GetSize() != 0);
139  }
140  virtual void LabelsOption(Option_t *option="h"); // *MENU*
141  void RotateTitle(Bool_t rotate=kTRUE); // *TOGGLE* *GETTER=GetRotateTitle
142  virtual void SaveAttributes(std::ostream &out, const char *name, const char *subname);
143  virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax);
144  virtual void Set(Int_t nbins, const Float_t *xbins);
145  virtual void Set(Int_t nbins, const Double_t *xbins);
146  virtual void SetBinLabel(Int_t bin, const char *label);
147  void SetDecimals(Bool_t dot = kTRUE); // *TOGGLE* *GETTER=GetDecimals
148  virtual void SetDefaults();
149  virtual void SetDrawOption(Option_t * /*option*/ ="") { }
150  void ChangeLabel(Int_t labNum=0, Double_t labAngle = -1.,
151  Double_t labSize = -1., Int_t labAlign = -1,
152  Int_t labColor = -1 , Int_t labFont = -1,
153  TString labText = ""); // *MENU*
154  virtual void SetLimits(Double_t xmin, Double_t xmax) { /* set axis limits */ fXmin = xmin; fXmax = xmax; } // *MENU*
155  void SetMoreLogLabels(Bool_t more=kTRUE); // *TOGGLE* *GETTER=GetMoreLogLabels
156  void SetNoExponent(Bool_t noExponent=kTRUE); // *TOGGLE* *GETTER=GetNoExponent
157  virtual void SetParent(TObject *obj) {fParent = obj;}
158  virtual void SetRange(Int_t first=0, Int_t last=0); // *MENU*
159  virtual void SetRangeUser(Double_t ufirst, Double_t ulast); // *MENU*
160  virtual void SetTicks(Option_t *option="+"); // *MENU*
161  virtual void SetTimeDisplay(Int_t value) {fTimeDisplay = (value != 0);} // *TOGGLE*
162  virtual void SetTimeFormat(const char *format=""); // *MENU*
163  virtual void SetTimeOffset(Double_t toffset, Option_t *option="local");
164  virtual void UnZoom(); // *MENU*
165  virtual void ZoomOut(Double_t factor=0, Double_t offset=0); // *MENU*
166 
167  ClassDef(TAxis,10) //Axis class
168 };
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Center axis labels. If center = kTRUE axis labels will be centered
172 /// (hori axes only) on the bin center default is to center on the primary tick marks
173 /// This option does not make sense if there are more bins than tick marks
174 
175 inline void TAxis::CenterLabels(Bool_t center)
176 {
177  SetBit(kCenterLabels, center);
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Center axis title. If center = kTRUE axis title will be centered
182 /// default is right adjusted
183 
184 inline void TAxis::CenterTitle(Bool_t center)
185 {
186  SetBit(kCenterTitle, center);
187 }
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// Rotate title by 180 degrees. By default the title is drawn right adjusted.
191 /// If rotate is TRUE, the title is left adjusted at the end of the axis and rotated by 180 degrees
192 
193 inline void TAxis::RotateTitle(Bool_t rotate)
194 {
195  SetBit(kRotateTitle, rotate);
196 }
197 
198 ////////////////////////////////////////////////////////////////////////////////
199 /// Sets the decimals flag
200 /// By default, blank characters are stripped, and then the label is correctly aligned.
201 /// If the dot is the last character of the string, it is also stripped, unless this option is specified.
202 
203 inline void TAxis::SetDecimals(Bool_t dot) {
204  SetBit(kDecimals, dot);
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Set the kMoreLogLabels bit flag
209 /// When this option is selected more labels are drawn when in log scale and there is a small number
210 /// of decades (<3).
211 /// The flag (in fBits) is passed to the drawing function TGaxis::PaintAxis
212 
214 {
215  SetBit(kMoreLogLabels, more);
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Set the NoExponent flag
220 /// By default, an exponent of the form 10^N is used when the label value are either all very small or very large.
221 /// The flag (in fBits) is passed to the drawing function TGaxis::PaintAxis
222 
223 inline void TAxis::SetNoExponent(Bool_t noExponent)
224 {
225  SetBit(kNoExponent, noExponent);
226 }
227 
228 
229 #endif
230 
TAxis::GetBinLabel
const char * GetBinLabel(Int_t bin) const
Return label for bin.
Definition: TAxis.cxx:440
TAxis::operator=
TAxis & operator=(const TAxis &)
Assignment operator.
Definition: TAxis.cxx:113
TAxis::kNoExponent
@ kNoExponent
Definition: TAxis.h:66
TAxis
Class to manage histogram axis.
Definition: TAxis.h:30
TAxis::SetParent
virtual void SetParent(TObject *obj)
Definition: TAxis.h:157
TAxis::fLabels
THashList * fLabels
Object owning this axis.
Definition: TAxis.h:43
first
Definition: first.py:1
TAxis::DrawClone
virtual TObject * DrawClone(Option_t *="") const
Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad...
Definition: TAxis.h:100
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TAxis::SetTimeOffset
virtual void SetTimeOffset(Double_t toffset, Option_t *option="local")
Change the time offset If option = "gmt", set display mode to GMT.
Definition: TAxis.cxx:1046
TObject::TestBit
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
TAxis::GetBinLowEdge
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:518
TAxis::Set
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition: TAxis.cxx:731
TAxis::SaveAttributes
virtual void SaveAttributes(std::ostream &out, const char *name, const char *subname)
Save axis attributes as C++ statement(s) on output stream out.
Definition: TAxis.cxx:661
TAxis::fFirst
Int_t fFirst
Definition: TAxis.h:37
TAxis::GetDecimals
Bool_t GetDecimals() const
Definition: TAxis.h:116
TAxis::CanExtend
Bool_t CanExtend() const
Definition: TAxis.h:82
UShort_t
unsigned short UShort_t
Definition: RtypesCore.h:40
TAxis::SetLimits
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition: TAxis.h:154
TString::Data
const char * Data() const
Definition: TString.h:369
TAxis::TAxis
TAxis()
Default constructor.
Definition: TAxis.cxx:49
TAxis::kIsInteger
@ kIsInteger
Definition: TAxis.h:71
TAxis::SetRangeUser
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Set the viewing range for the axis from ufirst to ulast (in user coordinates, that is,...
Definition: TAxis.cxx:946
TAxis::kPalette
@ kPalette
Definition: TAxis.h:65
xmax
float xmax
Definition: THbookFile.cxx:95
TNamed.h
TAxis::GetCenterLabels
Bool_t GetCenterLabels() const
Definition: TAxis.h:114
TAttAxis.h
TAxis::GetFirst
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:458
Float_t
float Float_t
Definition: RtypesCore.h:57
TAxis::SetDrawOption
virtual void SetDrawOption(Option_t *="")
Set drawing option for object.
Definition: TAxis.h:149
Int_t
int Int_t
Definition: RtypesCore.h:45
TAxis::GetBinCenter
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:478
TAxis::SetTimeFormat
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition: TAxis.cxx:1020
TAxis::GetBinUpEdge
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:528
TAxis::fXmax
Double_t fXmax
Definition: TAxis.h:35
TAxis::fBits2
UShort_t fBits2
Definition: TAxis.h:39
TAxis::kCenterTitle
@ kCenterTitle
Definition: TAxis.h:62
x
Double_t x[n]
Definition: legend1.C:17
TAxis::Copy
virtual void Copy(TObject &axis) const
Copy axis structure to another axis.
Definition: TAxis.cxx:210
TAxis::GetTimeDisplay
virtual Bool_t GetTimeDisplay() const
Definition: TAxis.h:126
TAxis::SetTimeDisplay
virtual void SetTimeDisplay(Int_t value)
Definition: TAxis.h:161
TAxis::CenterTitle
void CenterTitle(Bool_t center=kTRUE)
Center axis title.
Definition: TAxis.h:184
TAxis::SetNoAlphanumeric
void SetNoAlphanumeric(Bool_t noalpha=kTRUE)
Definition: TAxis.h:87
TString
Definition: TString.h:136
TAxis::ImportAttributes
virtual void ImportAttributes(const TAxis *axis)
Copy axis attributes to this.
Definition: TAxis.cxx:631
TAxis::GetTicks
virtual const char * GetTicks() const
Return the ticks option (see SetTicks)
Definition: TAxis.cxx:586
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TAxis::IsAlphanumeric
Bool_t IsAlphanumeric()
Definition: TAxis.h:84
TAxis::ExecuteEvent
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TAxis.cxx:281
TAxis::LabelsOption
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
Definition: TAxis.cxx:613
TAxis::GetLowEdge
virtual void GetLowEdge(Double_t *edge) const
Return an array with the low edge of all bins.
Definition: TAxis.cxx:562
TAxis::CenterLabels
void CenterLabels(Bool_t center=kTRUE)
Center axis labels.
Definition: TAxis.h:175
bool
TAxis::HasBinWithoutLabel
Bool_t HasBinWithoutLabel() const
this helper function checks if there is a bin without a label if all bins have labels,...
Definition: TAxis.cxx:597
TAxis::GetTitle
const char * GetTitle() const
Returns title of object.
Definition: TAxis.h:129
TNamed::fTitle
TString fTitle
Definition: TNamed.h:39
TAxis::GetParent
virtual TObject * GetParent() const
Definition: TAxis.h:123
TAxis::kCenterLabels
@ kCenterLabels
Definition: TAxis.h:63
TAxis::GetLabels
THashList * GetLabels() const
Definition: TAxis.h:117
TAxis::GetCenter
virtual void GetCenter(Double_t *center) const
Return an array with the center of all bins.
Definition: TAxis.cxx:553
TAxis::kTickMinus
@ kTickMinus
Definition: TAxis.h:60
TAxis::kMoreLogLabels
@ kMoreLogLabels
Definition: TAxis.h:72
TAxis::GetMoreLogLabels
Bool_t GetMoreLogLabels() const
Definition: TAxis.h:120
TAxis::SetRange
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition: TAxis.cxx:920
TArrayD.h
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TAxis::fTimeFormat
TString fTimeFormat
Definition: TAxis.h:41
TAxis::ChooseTimeFormat
const char * ChooseTimeFormat(Double_t axislength=0)
Choose a reasonable time format from the coordinates in the active pad and the number of divisions in...
Definition: TAxis.cxx:126
TAxis::GetXmin
Double_t GetXmin() const
Definition: TAxis.h:133
TAxis::kLabelsHori
@ kLabelsHori
Definition: TAxis.h:67
xmin
float xmin
Definition: THbookFile.cxx:95
TAxis::~TAxis
virtual ~TAxis()
Destructor.
Definition: TAxis.cxx:88
THashList
Definition: THashList.h:34
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
TAxis::kLabelsUp
@ kLabelsUp
Definition: TAxis.h:70
TAxis::kAxisRange
@ kAxisRange
Definition: TAxis.h:61
TAxis::kNotAlpha
@ kNotAlpha
Definition: TAxis.h:50
TNamed
Definition: TNamed.h:29
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TAxis::ChangeLabel
void ChangeLabel(Int_t labNum=0, Double_t labAngle=-1., Double_t labSize=-1., Int_t labAlign=-1, Int_t labColor=-1, Int_t labFont=-1, TString labText="")
Define new text attributes for the label number "labNum".
Definition: TAxis.cxx:873
TAxis::kTickPlus
@ kTickPlus
Definition: TAxis.h:59
TAxis::GetLast
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:469
TAxis::GetModifiedLabels
TList * GetModifiedLabels() const
Definition: TAxis.h:118
BIT
#define BIT(n)
Definition: Rtypes.h:85
TAxis::GetTimeFormat
virtual const char * GetTimeFormat() const
Definition: TAxis.h:127
TAxis::kAlphanumeric
@ kAlphanumeric
Definition: TAxis.h:48
TAxis::SetCanExtend
void SetCanExtend(Bool_t canExtend)
Definition: TAxis.h:86
TAxis::GetRotateTitle
Bool_t GetRotateTitle() const
Definition: TAxis.h:124
TAxis::SetTicks
virtual void SetTicks(Option_t *option="+")
Set ticks orientation.
Definition: TAxis.cxx:972
TAxis::SetDefaults
virtual void SetDefaults()
Set axis default values (from TStyle)
Definition: TAxis.cxx:803
TAxis::IsVariableBinSize
Bool_t IsVariableBinSize() const
Definition: TAxis.h:136
TAxis::UnZoom
virtual void UnZoom()
Reset first & last bin to the full range.
Definition: TAxis.cxx:1132
TAxis::fModLabs
TList * fModLabs
Definition: TAxis.h:44
TAxis::kLabelsDown
@ kLabelsDown
Definition: TAxis.h:69
TAxis::SetAlphanumeric
void SetAlphanumeric(Bool_t alphanumeric=kTRUE)
Set axis alphanumeric.
Definition: TAxis.cxx:779
TAxis::GetNoExponent
Bool_t GetNoExponent() const
Definition: TAxis.h:122
TAxis::fXbins
TArrayD fXbins
Definition: TAxis.h:36
TAxis::SetBinLabel
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:823
Double_t
double Double_t
Definition: RtypesCore.h:59
TAxis::kLabelsVert
@ kLabelsVert
Definition: TAxis.h:68
TAxis::CanBeAlphanumeric
Bool_t CanBeAlphanumeric()
Definition: TAxis.h:83
TAxis::SetNoExponent
void SetNoExponent(Bool_t noExponent=kTRUE)
Set the NoExponent flag By default, an exponent of the form 10^N is used when the label value are eit...
Definition: TAxis.h:223
TAxis::fNbins
Int_t fNbins
Definition: TAxis.h:33
TAxis::fTimeDisplay
Bool_t fTimeDisplay
Definition: TAxis.h:40
TAxis::SetMoreLogLabels
void SetMoreLogLabels(Bool_t more=kTRUE)
Set the kMoreLogLabels bit flag When this option is selected more labels are drawn when in log scale ...
Definition: TAxis.h:213
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TAxis::FindBin
virtual Int_t FindBin(Double_t x) const
Definition: TAxis.h:103
TAttAxis
Definition: TAttAxis.h:18
TAxis::Delete
virtual void Delete(Option_t *="")
Delete this object.
Definition: TAxis.h:98
name
char name[80]
Definition: TGX11.cxx:110
TAxis::GetTimeFormatOnly
virtual const char * GetTimeFormatOnly() const
Return only the time format from the string fTimeFormat.
Definition: TAxis.cxx:571
TAxis::FindBin
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:293
TAxis::SetDecimals
void SetDecimals(Bool_t dot=kTRUE)
Sets the decimals flag By default, blank characters are stripped, and then the label is correctly ali...
Definition: TAxis.h:203
TAxis::kRotateTitle
@ kRotateTitle
Definition: TAxis.h:64
TAxis::FindFixBin
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:419
TAxis::fParent
TObject * fParent
Definition: TAxis.h:42
TAxis::GetCenterTitle
Bool_t GetCenterTitle() const
Definition: TAxis.h:115
TAxis::GetBinCenterLog
virtual Double_t GetBinCenterLog(Int_t bin) const
Return center of bin in log With a log-equidistant binning for a bin with low and up edges,...
Definition: TAxis.cxx:501
TAxis::RotateTitle
void RotateTitle(Bool_t rotate=kTRUE)
Rotate title by 180 degrees.
Definition: TAxis.h:193
TAxis::fXmin
Double_t fXmin
Definition: TAxis.h:34
TAxis::GetXmax
Double_t GetXmax() const
Definition: TAxis.h:134
TArrayD
Definition: TArrayD.h:27
TAxis::ZoomOut
virtual void ZoomOut(Double_t factor=0, Double_t offset=0)
Zoom out by a factor of 'factor' (default =2) uses previous zoom factor by default Keep center define...
Definition: TAxis.cxx:1204
TAxis::GetXbins
const TArrayD * GetXbins() const
Definition: TAxis.h:130
TAxis::kCanExtend
@ kCanExtend
Definition: TAxis.h:49
TAxis::DistancetoPrimitive
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to an axis.
Definition: TAxis.cxx:265
TObject::EStatusBits
EStatusBits
Definition: TObject.h:57
TAxis::GetNbins
Int_t GetNbins() const
Definition: TAxis.h:121
TList
Definition: TList.h:44
TAxis::GetBinWidth
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition: TAxis.cxx:540
TArray::GetSize
Int_t GetSize() const
Definition: TArray.h:47
TAxis::kDecimals
@ kDecimals
Definition: TAxis.h:58
int
TAxis::fLast
Int_t fLast
Definition: TAxis.h:38