Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TAxis.cxx
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#include "TAxis.h"
13#include "TVirtualPad.h"
14#include "TStyle.h"
15#include "TError.h"
16#include "THashList.h"
17#include "TList.h"
18#include "TAxisModLab.h"
19#include "TH1.h"
20#include "TObjString.h"
21#include "TDatime.h"
22#include "TTimeStamp.h"
23#include "TBuffer.h"
24#include "TMath.h"
25#include "THLimitsFinder.h"
26#include "strlcpy.h"
27#include "snprintf.h"
28
29#include <iostream>
30#include <cmath>
31#include <ctime>
32#include <cassert>
33
34
35////////////////////////////////////////////////////////////////////////////////
36/** \class TAxis
37 \ingroup Histograms
38 \brief Class to manage histogram axis
39
40This class manages histogram axis. It is referenced by TH1 and TGraph.
41To make a graphical representation of an histogram axis, this class
42references the TGaxis class. TAxis supports axis with fixed or variable bin sizes.
43Labels may be associated to individual bins.
44See examples of various axis representations drawn by class TGaxis.
45*///////////////////////////////////////////////////////////////////////////////
46
47////////////////////////////////////////////////////////////////////////////////
48/// Default constructor.
49
51{
52 fNbins = 1;
53 fXmin = 0;
54 fXmax = 1;
55 fFirst = 0;
56 fLast = 0;
57 fBits2 = 0;
58 fTimeDisplay = false;
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Axis constructor for axis with fix bin size
63
65{
66 Set(nbins,xlow,xup);
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Axis constructor for variable bin size
71
72TAxis::TAxis(Int_t nbins,const Double_t *xbins)
73{
74 Set(nbins,xbins);
75}
76
77TAxis::TAxis(std::vector<double> const &bins):
78 TAxis(bins.size()-1, bins.data())
79{}
81////////////////////////////////////////////////////////////////////////////////
82/// Destructor.
85{
86 if (fLabels) {
87 fLabels->Delete();
88 delete fLabels;
89 fLabels = nullptr;
90 }
91 if (fModLabs) {
93 delete fModLabs;
94 fModLabs = nullptr;
95 }
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Copy constructor.
100
101TAxis::TAxis(const TAxis &axis) : TNamed(axis), TAttAxis(axis)
102{
103 fParent = nullptr;
104 fLabels = nullptr;
105 fModLabs = nullptr;
106
107 axis.TAxis::Copy(*this);
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Assignment operator.
112
114{
115 if (this != &axis)
116 axis.TAxis::Copy(*this);
117 return *this;
118}
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// Choose a reasonable time format from the coordinates in the active pad
123/// and the number of divisions in this axis
124/// If orientation = "X", the horizontal axis of the pad will be used for ref.
125/// If orientation = "Y", the vertical axis of the pad will be used for ref.
126
128{
129 const char *formatstr = nullptr;
130 Int_t reasformat = 0;
131 Int_t ndiv,nx1,nx2,n;
134
135 if (!axislength) {
136 length = gPad->GetUxmax() - gPad->GetUxmin();
137 } else {
139 }
140
141 ndiv = GetNdivisions();
142 if (ndiv > 1000) {
143 nx2 = ndiv/100;
144 nx1 = TMath::Max(1, ndiv%100);
145 ndiv = 100*nx2 + Int_t(Double_t(nx1)*gPad->GetAbsWNDC());
146 }
147 ndiv = TMath::Abs(ndiv);
148 n = ndiv - (ndiv/100)*100;
149 awidth = length/n;
150
151// width in seconds ?
152 if (awidth>=.5) {
153 reasformat = 1;
154// width in minutes ?
155 if (awidth>=30) {
156 awidth /= 60; reasformat = 2;
157// width in hours ?
158 if (awidth>=30) {
159 awidth /=60; reasformat = 3;
160// width in days ?
161 if (awidth>=12) {
162 awidth /= 24; reasformat = 4;
163// width in months ?
164 if (awidth>=15.218425) {
165 awidth /= 30.43685; reasformat = 5;
166// width in years ?
167 if (awidth>=6) {
168 awidth /= 12; reasformat = 6;
169 if (awidth>=2) {
170 awidth /= 12; reasformat = 7;
171 }
172 }
173 }
174 }
175 }
176 }
177 }
178// set reasonable format
179 switch (reasformat) {
180 case 0:
181 formatstr = "%S";
182 break;
183 case 1:
184 formatstr = "%Mm%S";
185 break;
186 case 2:
187 formatstr = "%Hh%M";
188 break;
189 case 3:
190 formatstr = "%d-%Hh";
191 break;
192 case 4:
193 formatstr = "%d/%m";
194 break;
195 case 5:
196 formatstr = "%d/%m/%y";
197 break;
198 case 6:
199 formatstr = "%d/%m/%y";
200 break;
201 case 7:
202 formatstr = "%m/%y";
203 break;
204 }
205 return formatstr;
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Copy axis structure to another axis
210
211void TAxis::Copy(TObject &obj) const
212{
213 TAxis &axis = static_cast<TAxis &>(obj);
214 TNamed::Copy(axis);
215 TAttAxis::Copy(axis);
216 axis.fNbins = fNbins;
217 axis.fXmin = fXmin;
218 axis.fXmax = fXmax;
219 axis.fFirst = fFirst;
220 axis.fLast = fLast;
221 axis.fBits2 = fBits2;
222 fXbins.Copy(axis.fXbins);
225 axis.fParent = fParent;
226 if (axis.fLabels) {
227 axis.fLabels->Delete();
228 delete axis.fLabels;
229 axis.fLabels = nullptr;
230 }
231 if (fLabels) {
232 //Properly handle case where not all bins have labels
233 axis.fLabels = new THashList(axis.fNbins, 3);
234 TIter next(fLabels);
235 while(auto label = (TObjString *)next()) {
236 TObjString *copyLabel = new TObjString(*label);
237 axis.fLabels->Add(copyLabel);
238 copyLabel->SetUniqueID(label->GetUniqueID());
239 }
240 }
241 if (axis.fModLabs) {
242 axis.fModLabs->Delete();
243 delete axis.fModLabs;
244 axis.fModLabs = nullptr;
245 }
246 if (fModLabs) {
247 axis.fModLabs = new TList();
248 TIter next(fModLabs);
249 while(auto modlabel = (TAxisModLab *)next()) {
252 copyModLabel->SetUniqueID(modlabel->GetUniqueID());
253 }
254 }
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Compute distance from point px,py to an axis
259
261{
262 return 9999;
263}
264
265////////////////////////////////////////////////////////////////////////////////
266/// Execute action corresponding to one event
267///
268/// This member function is called when an axis is clicked with the locator.
269/// The axis range is set between the position where the mouse is pressed
270/// and the position where it is released.
271/// If the mouse position is outside the current axis range when it is released
272/// the axis is unzoomed with the corresponding proportions.
273/// Note that the mouse does not need to be in the pad or even canvas
274/// when it is released.
275
277{
278 if (!gPad) return;
279 gPad->ExecuteEventAxis(event,px,py,this);
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Find bin number corresponding to abscissa `x`. NOTE: this method does not work with alphanumeric bins !!!
284///
285/// If `x` is underflow or overflow, attempt to extend the axis if TAxis::kCanExtend is true.
286/// Otherwise, return `0` or `fNbins+1`.
287///
288/// @note The underflow bin (`0`) is for any `x` strictly smaller than `fXmin`,
289/// whereas the overflow bin (`nbins+1`) is for any `x` greater or equal than `fXmax`,
290/// as well as for `NaN`. The first regular bin (`1`) is for any `x`
291/// greater or equal than `fXmin` and strictly smaller than `fXmin + binwidth`, and so on.
292
294{
295 Int_t bin;
296 // NOTE: This should not be allowed for Alphanumeric histograms,
297 // but it is heavily used (legacy) in the TTreePlayer to fill alphanumeric histograms.
298 // but in case of alphanumeric do-not extend the axis. It makes no sense
299 if (IsAlphanumeric() && gDebug) Info("FindBin","Numeric query on alphanumeric axis - Sorting the bins or extending the axes / rebinning can alter the correspondence between the label and the bin interval.");
300 if (x < fXmin) { //*-* underflow
301 bin = 0;
302 if (fParent == nullptr) return bin;
303 if (!CanExtend() || IsAlphanumeric() ) return bin;
304 ((TH1*)fParent)->ExtendAxis(x,this);
305 return FindFixBin(x);
306 } else if ( !(x < fXmax)) { //*-* overflow (note the way to catch NaN)
307 bin = fNbins+1;
308 if (fParent == nullptr) return bin;
309 if (!CanExtend() || IsAlphanumeric() ) return bin;
310 ((TH1*)fParent)->ExtendAxis(x,this);
311 return FindFixBin(x);
312 } else {
313 if (!fXbins.fN) { //*-* fix bins
314 const double width = (fXmax-fXmin)/fNbins;
315 const int approxBin = (x-fXmin) / width; // Might be one unit too small/large due to limited precision of subtraction
316 bin = 1 + approxBin - (x < fXmin + width*approxBin) + (fXmin + width*(approxBin+1) <= x);
317 } else { //*-* variable bin sizes
318 //for (bin =1; x >= fXbins.fArray[bin]; bin++);
320 }
321 }
322 return bin;
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// Find bin number with label.
327/// If the List of labels does not exist create it and make the axis alphanumeric
328/// If one wants just to add a single label- just call TAxis::SetBinLabel
329/// If label is not in the list of labels do the following depending on the
330/// bit TAxis::kCanExtend; of the axis.
331/// - if the bit is set add the new label and if the number of labels exceeds
332/// the number of bins, double the number of bins via TH1::LabelsInflate
333/// - if the bit is not set and the histogram has labels in each bin
334/// set the bit automatically and consider the histogram as alphanumeric
335/// if histogram has only some bins with labels then the histogram is not
336/// consider alphanumeric and return -1
337///
338/// -1 is returned only when the Axis has no parent histogram
339
340Int_t TAxis::FindBin(const char *label)
341{
342 //create list of labels if it does not exist yet
343 if (!fLabels) {
344 if (!fParent) return -1;
345 fLabels = new THashList(fNbins,3);
346 // we set the axis alphanumeric
347 // when list of labels does not exist
348 // do we want to do this also when histogram is not empty ?????
349 if (CanBeAlphanumeric() ) {
352 if (fXmax <= fXmin) {
353 //L.M. Dec 2010 in case of no min and max specified use 0 ->NBINS
354 fXmin = 0;
355 fXmax = fNbins;
356 }
357 }
358 }
359
360 // search for label in the existing list and return it if it exists
361 TObjString *obj = (TObjString*)fLabels->FindObject(label);
362 if (obj) return (Int_t)obj->GetUniqueID();
363
364 // if labels is not in the list and we have already labels
365 if (!IsAlphanumeric()) {
366 // if bins without labels exist or if the axis cannot be set to alphanumeric
368 Info("FindBin","Label %s is not in the list and the axis is not alphanumeric - ignore it",label);
369 return -1;
370 }
371 else {
372 Info("FindBin","Label %s not in the list. It will be added to the histogram",label);
375 }
376 }
377
378 //Not yet in the list. Can we extend the axis ?
380 // {
381 // if (gDebug>0)
382 // Info("FindBin","Label %s is not in the list and the axis cannot be extended - the entry will be added in the underflow bin",label);
383 // return 0;
384 // }
385
387
388 //may be we have to resize the histogram (doubling number of channels)
389 if (n >= fNbins) ((TH1*)fParent)->LabelsInflate(GetName());
390
391 //add new label to the list: assign bin number
392 obj = new TObjString(label);
393 fLabels->Add(obj);
394 obj->SetUniqueID(n+1);
395 return n+1;
396}
397
398////////////////////////////////////////////////////////////////////////////////
399/// Find bin number with label.
400/// If the List of labels does not exist or the label does not exist just return -1 .
401/// Do not attempt to modify the axis. This is different than FindBin
402
403Int_t TAxis::FindFixBin(const char *label) const
404{
405 //create list of labels if it does not exist yet
406 if (!fLabels) return -1;
407
408 // search for label in the existing list and return it if it exists
409 TObjString *obj = (TObjString*)fLabels->FindObject(label);
410 if (obj) return (Int_t)obj->GetUniqueID();
411 return -1;
412}
413
414
415////////////////////////////////////////////////////////////////////////////////
416/// Find bin number corresponding to abscissa `x`
417///
418/// Identical to TAxis::FindBin except that if `x` is an underflow/overflow
419/// no attempt is made to extend the axis.
420/// @see TAxis::FindBin
421
423{
424 Int_t bin;
425 if (x < fXmin) { //*-* underflow
426 bin = 0;
427 } else if ( !(x < fXmax)) { //*-* overflow (note the way to catch NaN)
428 bin = fNbins+1;
429 } else {
430 if (!fXbins.fN) { //*-* fix bins
431 const double width = (fXmax-fXmin)/fNbins;
432 const int approxBin = (x-fXmin) / width; // Might be one unit too small/large due to limited precision of subtraction
433 bin = 1 + approxBin - (x < fXmin + width*approxBin) + (fXmin + width*(approxBin+1) <= x);
434 } else { //*-* variable bin sizes
436 }
437 }
438 return bin;
439}
440
441////////////////////////////////////////////////////////////////////////////////
442/// Return label for bin
443
444const char *TAxis::GetBinLabel(Int_t bin) const
445{
446 if (!fLabels) return "";
447 if (bin <= 0 || bin > fNbins) return "";
448 TIter next(fLabels);
449 TObjString *obj;
450 while ((obj=(TObjString*)next())) {
451 Int_t binid = (Int_t)obj->GetUniqueID();
452 if (binid == bin) return obj->GetName();
453 }
454 return "";
455}
456
457////////////////////////////////////////////////////////////////////////////////
458/// Return first bin on the axis
459/// i.e. 1 if no range defined
460/// \note in some cases a zero is returned (see TAxis::SetRange)
461
463{
464 if (!TestBit(kAxisRange)) return 1;
465 return fFirst;
466}
467
468////////////////////////////////////////////////////////////////////////////////
469/// Return last bin on the axis
470/// i.e. fNbins if no range defined
471/// \note in some cases a zero is returned (see TAxis::SetRange)
472
474{
475 if (!TestBit(kAxisRange)) return fNbins;
476 return fLast;
477}
478
479////////////////////////////////////////////////////////////////////////////////
480/// Return center of bin
481
483{
485 if (!fXbins.fN || bin<1 || bin>fNbins) {
487 return fXmin + (bin - 0.5) * binwidth;
488 } else {
489 binwidth = fXbins.fArray[bin] - fXbins.fArray[bin-1];
490 return fXbins.fArray[bin-1] + 0.5*binwidth;
491 }
492}
493
494////////////////////////////////////////////////////////////////////////////////
495/// Return center of bin in log
496/// With a log-equidistant binning for a bin with low and up edges, the mean is :
497/// 0.5*(ln low + ln up) i.e. sqrt(low*up) in logx (e.g. sqrt(10^0*10^2) = 10).
498/// Imagine a bin with low=1 and up=100 :
499/// - the center in lin is (100-1)/2=50.5
500/// - the center in log would be sqrt(1*100)=10 (!=log(50.5))
501///
502/// NB: if the low edge of the bin is negative, the function returns the bin center
503/// as computed by TAxis::GetBinCenter
504
506{
507 Double_t low,up;
508 if (!fXbins.fN || bin<1 || bin>fNbins) {
510 low = fXmin + (bin-1) * binwidth;
511 up = low+binwidth;
512 } else {
513 low = fXbins.fArray[bin-1];
514 up = fXbins.fArray[bin];
515 }
516 if (low <=0 ) return GetBinCenter(bin);
517 return TMath::Sqrt(low*up);
518}
519////////////////////////////////////////////////////////////////////////////////
520/// Return low edge of bin
521
523{
524 if (fXbins.fN && bin > 0 && bin <=fNbins) return fXbins.fArray[bin-1];
526 return fXmin + (bin-1) * binwidth;
527}
528
529////////////////////////////////////////////////////////////////////////////////
530/// Return up edge of bin
531
533{
536 return fXmin + bin*binwidth;
537 }
538 return fXbins.fArray[bin];
539}
540
541////////////////////////////////////////////////////////////////////////////////
542/// Return bin width
543///
544/// If `bin > fNbins` (overflow bin) or `bin < 1` (underflow bin), the returned bin width is `(fXmax - fXmin) / fNbins`.
545
547{
548 if (fNbins <= 0) return 0;
549 if (fXbins.fN <= 0 || bin >fNbins || bin <1)
550 return (fXmax - fXmin) / Double_t(fNbins);
551 return fXbins.fArray[bin] - fXbins.fArray[bin-1];
552}
553
554
555////////////////////////////////////////////////////////////////////////////////
556/// Return an array with the center of all bins
557
558void TAxis::GetCenter(Double_t *center) const
559{
560 for (Int_t bin = 1; bin <= fNbins; bin++)
561 *(center + bin - 1) = GetBinCenter(bin);
562}
563
564////////////////////////////////////////////////////////////////////////////////
565/// Return an array with the low edge of all bins
566
568{
569 for (Int_t bin = 1; bin <= fNbins; bin++)
570 *(edge + bin - 1) = GetBinLowEdge(bin);
571}
572
573////////////////////////////////////////////////////////////////////////////////
574/// Return the number of axis labels.
575///
576/// It is sometimes useful to know the number of labels on an axis. For instance
577/// when changing the labels with TAxis::ChangeLabel. The number of labels is equal
578/// to `the_number_of_divisions + 1`. By default the number of divisions is
579/// optimised to show a coherent labeling of the main tick marks. After optimisation the
580/// real number of divisions will be smaller or equal to number of divisions requested.
581/// In order to turn off the labeling optimization, it is enough to give a negative
582/// number of divisions to TAttAxis::SetNdivisions. The absolute value of this number will be use as
583/// the exact number of divisions. This method takes the two cases (optimised or not) into
584/// account.
585
587{
588 if (fNdivisions > 0) {
589 Int_t divxo = 0;
590 Double_t x1o = 0.;
591 Double_t x2o = 0.;
592 Double_t bwx = 0.;
594 return divxo+1;
595 } else {
597 return divx%100+1;
598 }
599}
600
601////////////////////////////////////////////////////////////////////////////////
602/// Return *only* the time format from the string fTimeFormat
603
604const char *TAxis::GetTimeFormatOnly() const
605{
606 static TString timeformat;
607 Int_t idF = fTimeFormat.Index("%F");
608 if (idF>=0) {
610 } else {
612 }
613 return timeformat.Data();
614}
615
616////////////////////////////////////////////////////////////////////////////////
617/// Return the time offset in GMT.
618
620
621 Int_t idF = fTimeFormat.Index("%F")+2;
622 if (idF<2) {
623 Warning("GetGMTimeOffset","Time format is not set!");
624 return 0;
625 }
627 if (stime.Length() != 19) {
628 Warning("GetGMTimeOffset","Bad time format!");
629 return 0;
630 }
631
632 TDatime datime(stime.Data());
633 return datime.Convert(kTRUE); // Convert to unix gmt time
634}
635
636////////////////////////////////////////////////////////////////////////////////
637/// Return the ticks option (see SetTicks)
638
639const char *TAxis::GetTicks() const
640{
641 if (TestBit(kTickPlus) && TestBit(kTickMinus)) return "+-";
642 if (TestBit(kTickMinus)) return "-";
643 if (TestBit(kTickPlus)) return "+";
644 return "";
645}
646
647////////////////////////////////////////////////////////////////////////////////
648/// This helper function checks if there is a bin without a label
649/// if all bins have labels, the axis can / will become alphanumeric
650
652{
653 return fLabels->GetSize() != fNbins;
654}
655
656////////////////////////////////////////////////////////////////////////////////
657/// Set option(s) to draw axis with labels
658/// option can be:
659/// - "a" sort by alphabetic order
660/// - ">" sort by decreasing values
661/// - "<" sort by increasing values
662/// - "h" draw labels horizontal
663/// - "v" draw labels vertical
664/// - "u" draw labels up (end of label right adjusted)
665/// - "d" draw labels down (start of label left adjusted)
666
668{
669 if (!fLabels) {
670 Warning("Sort","Cannot sort. No labels");
671 return;
672 }
673 TH1 *h = (TH1*)GetParent();
674 if (!h) {
675 Error("Sort","Axis has no parent");
676 return;
677 }
678
679 h->LabelsOption(option,GetName());
680}
681
682////////////////////////////////////////////////////////////////////////////////
683/// Copy axis attributes to this
684
709
710
711
712////////////////////////////////////////////////////////////////////////////////
713/// Save axis attributes as C++ statement(s) on output stream out
714
715void TAxis::SaveAttributes(std::ostream &out, const char *name, const char *subname)
716{
717 auto prefix = TString::Format(" %s%s->", name, subname);
718
719 if (strlen(GetTitle()))
720 out << prefix << "SetTitle(\"" << TString(GetTitle()).ReplaceSpecialCppChars() << "\");\n";
721 if (fTimeDisplay) {
722 out << prefix << "SetTimeDisplay(1);\n";
723 out << prefix << "SetTimeFormat(\"" << GetTimeFormat() << "\");\n";
724 }
725 if (fLabels) {
726 TIter next(fLabels);
727 while (auto obj = static_cast<TObjString *>(next())) {
728 out << prefix << "SetBinLabel(" << obj->GetUniqueID() << ", \""
729 << TString(obj->GetName()).ReplaceSpecialCppChars() << "\");\n";
730 }
731 }
732
733 if (fFirst || fLast)
734 out << prefix << "SetRange(" << fFirst << ", " << fLast << ");\n";
735
736 if (TestBit(kLabelsHori))
737 out << prefix << "SetBit(TAxis::kLabelsHori);\n";
738
739 if (TestBit(kLabelsVert))
740 out << prefix << "SetBit(TAxis::kLabelsVert);\n";
741
742 if (TestBit(kLabelsDown))
743 out << prefix << "SetBit(TAxis::kLabelsDown);\n";
744
745 if (TestBit(kLabelsUp))
746 out << prefix << "SetBit(TAxis::kLabelsUp);\n";
747
749 out << prefix << "CenterLabels(true);\n";
750
752 out << prefix << "CenterTitle(true);\n";
753
755 out << prefix << "RotateTitle(true);\n";
756
757 if (TestBit(kDecimals))
758 out << prefix << "SetDecimals();\n";
759
761 out << prefix << "SetMoreLogLabels();\n";
762
763 if (TestBit(kNoExponent))
764 out << prefix << "SetNoExponent();\n";
765
766 if (fModLabs) {
767 TIter next(fModLabs);
768 while (auto ml = static_cast<TAxisModLab *>(next())) {
769 if (ml->GetLabNum() == 0)
770 out << prefix << "ChangeLabelByValue(" << ml->GetLabValue();
771 else
772 out << prefix << "ChangeLabel(" << ml->GetLabNum();
773 out << ", " << ml->GetAngle() << ", " << ml->GetSize() << ", " << ml->GetAlign() << ", "
774 << TColor::SavePrimitiveColor(ml->GetColor()) << ", " << ml->GetFont() << ", \""
775 << TString(ml->GetText()).ReplaceSpecialCppChars() << "\");\n";
776 }
777 }
779}
780
781////////////////////////////////////////////////////////////////////////////////
782/// Initialize axis with fix bins
783///
784/// An error is printed if xup or xlow are infinite/nan
785/// (due to resulting undefined fixed bin width)
786///
787/// Set xup <= xlow to force the axis range and number of bins to be automatically
788/// deduced after buffer is full or BufferEmpty is called
789
790void TAxis::Set(Int_t nbins, Double_t xlow, Double_t xup)
791{
792 fNbins = nbins;
793 if (!std::isfinite(xlow) || !std::isfinite(xup))
794 Error("TAxis::Set", "Axis limits need to be finite numbers");
795 fXmin = xlow;
796 fXmax = xup;
797 if (!fParent) SetDefaults();
798 if (fXbins.fN > 0) fXbins.Set(0);
799}
800
801////////////////////////////////////////////////////////////////////////////////
802/// Initialize axis with variable bins
803///
804/// An error is printed if bin edges are not in strictly increasing order
805/// or if any of them is infinite or nan
806
807void TAxis::Set(Int_t nbins, const Float_t *xbins)
808{
809 Int_t bin;
810 fNbins = nbins;
811 fXbins.Set(fNbins+1);
812 for (bin = 0; bin <= fNbins; bin++) {
813 if (!std::isfinite(xbins[bin])) {
814 Error("TAxis::Set", "Bin edges need to be finite numbers. Use a large number instead.");
815 }
816 fXbins.fArray[bin] = xbins[bin];
817 }
818 for (bin=1; bin<= fNbins; bin++)
819 if (fXbins.fArray[bin] <= fXbins.fArray[bin - 1])
820 Error("TAxis::Set", "bin edges must be in increasing order");
821 fXmin = fXbins.fArray[0];
823 if (!fParent) SetDefaults();
824}
825
826////////////////////////////////////////////////////////////////////////////////
827/// Initialize axis with variable bins
828
829void TAxis::Set(Int_t nbins, const Double_t *xbins)
830{
831 Int_t bin;
832 fNbins = nbins;
833 fXbins.Set(fNbins+1);
834 for (bin=0; bin<= fNbins; bin++)
835 fXbins.fArray[bin] = xbins[bin];
836 for (bin=1; bin<= fNbins; bin++)
837 if (fXbins.fArray[bin] <= fXbins.fArray[bin - 1])
838 Error("TAxis::Set", "bin edges must be in increasing order");
839 fXmin = fXbins.fArray[0];
841 if (!fParent) SetDefaults();
842}
843
844////////////////////////////////////////////////////////////////////////////////
845/// Set axis alphanumeric
846
848{
850 else fBits2 &= ~kAlphanumeric;
851
852 // clear underflow and overflow (in an alphanumeric situation they do not make sense)
853 // NOTE: using AddBinContent instead of SetBinContent in order to not change
854 // the number of entries
855 //((TH1 *)fParent)->ClearUnderflowAndOverflow();
856 // L.M. 26.1.15 Keep underflow and overflows (see ROOT-7034)
857 if (gDebug && fParent) {
858 TH1 * h = dynamic_cast<TH1*>( fParent);
859 if (!h) return;
860 double s[TH1::kNstat];
861 h->GetStats(s);
862 if (s[0] != 0. && gDebug > 0)
863 Info("SetAlphanumeric","Cannot switch axis %s of histogram %s to alphanumeric: it has non-zero content",GetName(),h->GetName());
864 }
865}
866
867
868////////////////////////////////////////////////////////////////////////////////
869/// Set axis default values (from TStyle)
870
872{
873 fFirst = 0;
874 fLast = 0;
875 fBits2 = 0;
876 char name[2];
877 strlcpy(name,GetName(),2);
878 name[1] = 0;
880 fTimeDisplay = false;
882}
883
884////////////////////////////////////////////////////////////////////////////////
885/// Set label for bin.
886/// If no label list exists, it is created. If all the bins have labels, the
887/// axis becomes alphanumeric and extendable.
888/// New labels will not be added with the Fill method but will end-up in the
889/// underflow bin. See documentation of TAxis::FindBin(const char*)
890
891void TAxis::SetBinLabel(Int_t bin, const char *label)
892{
893 if (!fLabels) fLabels = new THashList(fNbins,3);
894
896 Error("SetBinLabel","Illegal bin number: %d",bin);
897 return;
898 }
899
900 // Check whether this bin already has a label.
901 TIter next(fLabels);
902 TObjString *obj;
903 while ((obj=(TObjString*)next())) {
904 if ( obj->GetUniqueID()==(UInt_t)bin ) {
905 // It does. Overwrite it.
906 obj->SetString(label);
907 // LM need to rehash the labels list (see ROOT-5025)
909 return;
910 }
911 }
912 // It doesn't. Add this new label.
913 obj = new TObjString(label);
914 fLabels->Add(obj);
915 obj->SetUniqueID((UInt_t)bin);
916
917 // check for Alphanumeric case (labels for each bin)
918 if (CanBeAlphanumeric() && fLabels->GetSize() == fNbins) {
921 }
922}
923
924////////////////////////////////////////////////////////////////////////////////
925/// Search for axis modifier by index or value
926
928{
929 if (!fModLabs)
930 return nullptr;
931
932 TIter next(fModLabs);
933 while (auto ml = (TAxisModLab*)next()) {
934 if (ml->GetLabNum() != num)
935 continue;
936
937 if ((num != 0) || (TMath::Abs(v - ml->GetLabValue()) <= eps))
938 return ml;
939 }
940
941 return nullptr;
942}
943
944
945////////////////////////////////////////////////////////////////////////////////
946/// Define new text attributes for the label number "labNum". It allows to do a
947/// fine tuning of the labels. All the attributes can be changed, even the
948/// label text itself.
949///
950/// \param[in] labNum Number of the label to be changed, negative numbers start from the end
951/// \param[in] labAngle New angle value
952/// \param[in] labSize New size (0 erase the label)
953/// \param[in] labAlign New alignment value
954/// \param[in] labColor New label color
955/// \param[in] labFont New label font
956/// \param[in] labText New label text
957///
958/// #### Notes:
959///
960/// - If an attribute should not be changed just give the value "-1".
961/// - If labnum=0 the list of modified labels is reset.
962/// - To erase a label set labSize to 0.
963/// - If labText is not specified or is an empty string, the text label is not changed.
964/// - To retrieve the number of axis labels use TAxis::GetNlabels.
965
968 const TString &labText)
969{
970 // Reset the list of modified labels.
971 if (labNum == 0) {
973 return;
974 }
975
976 if (!fModLabs) fModLabs = new TList();
977
979 if (!ml) {
980 ml = new TAxisModLab();
981 ml->SetLabNum(labNum);
982 fModLabs->Add(ml);
983 }
984
985 ml->SetAngle(labAngle);
986 ml->SetSize(labSize);
987 ml->SetAlign(labAlign);
988 ml->SetColor(labColor);
989 ml->SetFont(labFont);
990 ml->SetText(labText);
991}
992
993////////////////////////////////////////////////////////////////////////////////
994/// Define new text attributes for the label value "labValue". It allows to do a
995/// fine tuning of the labels. All the attributes can be changed, even the
996/// label text itself.
997///
998/// \param[in] labValue Axis value to be changed
999/// \param[in] labAngle New angle value
1000/// \param[in] labSize New size (0 erase the label)
1001/// \param[in] labAlign New alignment value
1002/// \param[in] labColor New label color
1003/// \param[in] labFont New label font
1004/// \param[in] labText New label text
1005///
1006/// #### Notes:
1007///
1008/// - If an attribute should not be changed just give the value "-1".
1009/// - If labnum=0 the list of modified labels is reset.
1010/// - To erase a label set labSize to 0.
1011/// - If labText is not specified or is an empty string, the text label is not changed.
1012/// - To retrieve the number of axis labels use TAxis::GetNlabels.
1013
1016 const TString &labText)
1017{
1018 if (!fModLabs) fModLabs = new TList();
1019
1020 TAxisModLab *ml = FindModLab(0, labValue, 0.);
1021 if (!ml) {
1022 ml = new TAxisModLab();
1023 ml->SetLabValue(labValue);
1024 fModLabs->Add(ml);
1025 }
1026
1027 ml->SetAngle(labAngle);
1028 ml->SetSize(labSize);
1029 ml->SetAlign(labAlign);
1030 ml->SetColor(labColor);
1031 ml->SetFont(labFont);
1032 ml->SetText(labText);
1033}
1034
1035////////////////////////////////////////////////////////////////////////////////
1036/// Set the viewing range for the axis using bin numbers.
1037///
1038/// \param first First bin of the range.
1039/// \param last Last bin of the range.
1040///
1041/// To set a range using the axis coordinates, use TAxis::SetRangeUser.
1042///
1043/// If `first == last == 0` or if `first > last` or if the range specified does
1044/// not intersect at all with the maximum available range `[0, fNbins + 1]`,
1045/// then the viewing range is reset by removing the bit TAxis::kAxisRange. In this
1046/// case, the functions TAxis::GetFirst() and TAxis::GetLast() will return 1
1047/// and fNbins.
1048///
1049/// If the range specified partially intersects with `[0, fNbins + 1]`, then the
1050/// intersection range is accepted. For instance, if `first == -2` and `last == fNbins`,
1051/// the accepted range will be `[0, fNbins]` (`fFirst = 0` and `fLast = fNbins`).
1052///
1053/// If `last > fNbins`, the overflow bin is included in the range and will be displayed during drawing.
1054/// If `first < 1`, the underflow bin is included in the range and will be displayed during drawing.
1055///
1056/// \note For historical reasons, SetRange(0,0) resets the range even though bin 0 is
1057/// technically reserved for the underflow; in order to set the range of the axis
1058/// so that it only includes the underflow, use `SetRange(-1,0)`.
1059/// \note This function will also restrict the fitting range
1060
1061void TAxis::SetRange(Int_t first, Int_t last)
1062{
1063
1064 Int_t nCells = fNbins + 1; // bins + overflow
1065
1066 // special reset range cases
1067 if (last < first || (first < 0 && last < 0) ||
1068 (first > nCells && last > nCells) || (first == 0 && last == 0)
1069 ) {
1070 fFirst = 1;
1071 fLast = fNbins;
1072 SetBit(kAxisRange, false);
1073 } else {
1074 fFirst = std::max(first, 0);
1075 fLast = std::min(last, nCells);
1076 SetBit(kAxisRange, true);
1077 }
1078}
1079
1080////////////////////////////////////////////////////////////////////////////////
1081/// Set the viewing range for the axis from `ufirst` to `ulast` (in user coordinates,
1082/// that is, the "natural" axis coordinates).
1083/// To set a range using the axis bin numbers, use TAxis::SetRange.
1084///
1085/// If `ulast > fXmax`, the overflow bin is included in the range and will be displayed during drawing.
1086/// If `ufirst < fXmin`, the underflow bin is included in the range and will be displayed during drawing.
1087///
1088/// \note This function will also restrict the fitting range
1089
1091{
1092 if (!strstr(GetName(),"xaxis")) {
1093 TH1 *hobj = (TH1*)GetParent();
1094 if (hobj &&
1095 ((hobj->GetDimension() == 2 && strstr(GetName(),"zaxis"))
1096 || (hobj->GetDimension() == 1 && strstr(GetName(),"yaxis")))) {
1097 hobj->SetMinimum(ufirst);
1098 hobj->SetMaximum(ulast);
1099 return;
1100 }
1101 }
1104 // fixes for numerical error and for https://savannah.cern.ch/bugs/index.php?99777
1105 if (GetBinUpEdge(ifirst) <= ufirst ) ifirst += 1;
1106 if (GetBinLowEdge(ilast) >= ulast ) ilast -= 1;
1108}
1109
1110////////////////////////////////////////////////////////////////////////////////
1111/// Set ticks orientation.
1112/// option = "+" ticks drawn on the "positive side" (default)
1113/// option = "-" ticks drawn on the "negative side"
1114/// option = "+-" ticks drawn on both sides
1115/// option = "" ticks will be drawn as whatever is defined as default. No bit is set internally.
1116
1124
1125////////////////////////////////////////////////////////////////////////////////
1126/// Change the format used for time plotting
1127///
1128/// The format string for date and time use the same options as the one used
1129/// in the standard strftime C function, i.e. :
1130/// for date :
1131///
1132/// %a abbreviated weekday name
1133/// %b abbreviated month name
1134/// %d day of the month (01-31)
1135/// %m month (01-12)
1136/// %y year without century
1137///
1138/// for time :
1139///
1140/// %H hour (24-hour clock)
1141/// %I hour (12-hour clock)
1142/// %p local equivalent of AM or PM
1143/// %M minute (00-59)
1144/// %S seconds (00-61)
1145/// %% %
1146///
1147/// This function allows also to define the time offset. It is done via %F
1148/// which should be appended at the end of the format string. The time
1149/// offset has the following format: 'yyyy-mm-dd hh:mm:ss'
1150/// Example:
1151///
1152/// h = new TH1F("Test","h",3000,0.,200000.);
1153/// h->GetXaxis()->SetTimeDisplay(1);
1154/// h->GetXaxis()->SetTimeFormat("%d\/%m\/%y%F2000-02-28 13:00:01");
1155///
1156/// This defines the time format being "dd/mm/yy" and the time offset as the
1157/// February 28th 2003 at 13:00:01
1158///
1159/// If %F is not specified, the time offset used will be the one defined by:
1160/// gStyle->SetTimeOffset. For example like that:
1161///
1162/// TDatime da(2003,02,28,12,00,00);
1163/// gStyle->SetTimeOffset(da.Convert());
1164
1166{
1168
1169 if (timeformat.Index("%F")>=0 || timeformat.IsNull()) {
1171 return;
1172 }
1173
1174 Int_t idF = fTimeFormat.Index("%F");
1175 if (idF>=0) {
1180 } else {
1183 }
1184}
1185
1186
1187////////////////////////////////////////////////////////////////////////////////
1188/// Change the time offset
1189/// If option = "gmt", set display mode to GMT.
1190
1192{
1193 TString opt = option;
1194 opt.ToLower();
1195
1196 char tmp[20];
1197 time_t timeoff;
1198 struct tm* utctis;
1199 Int_t idF = fTimeFormat.Index("%F");
1200 if (idF>=0) fTimeFormat.Remove(idF);
1201 fTimeFormat.Append("%F");
1202
1203 timeoff = (time_t)((Long_t)(toffset));
1204 // offset is always saved in GMT to allow file transport
1205 // to different time zones
1206 utctis = gmtime(&timeoff);
1207
1208 strftime(tmp,20,"%Y-%m-%d %H:%M:%S",utctis);
1209 fTimeFormat.Append(tmp);
1210
1211 // append the decimal part of the time offset
1213 snprintf(tmp,20,"s%g",ds);
1214 fTimeFormat.Append(tmp);
1215
1216 // add GMT/local option
1217 if (opt.Contains("gmt")) fTimeFormat.Append(" GMT");
1218}
1219
1220
1221////////////////////////////////////////////////////////////////////////////////
1222/// Stream an object of class TAxis.
1223
1225{
1226 if (R__b.IsReading()) {
1227 UInt_t R__s, R__c;
1228 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1229 if (R__v > 5) {
1230 R__b.ReadClassBuffer(TAxis::Class(), this, R__v, R__s, R__c);
1231 return;
1232 }
1233 //====process old versions before automatic schema evolution
1236 R__b >> fNbins;
1237 if (R__v < 5) {
1239 R__b >> xmin; fXmin = xmin;
1240 R__b >> xmax; fXmax = xmax;
1241 Float_t *xbins = nullptr;
1242 Int_t n = R__b.ReadArray(xbins);
1243 fXbins.Set(n);
1244 for (Int_t i=0;i<n;i++) fXbins.fArray[i] = xbins[i];
1245 delete [] xbins;
1246 } else {
1247 R__b >> fXmin;
1248 R__b >> fXmax;
1250 }
1251 if (R__v > 2) {
1252 R__b >> fFirst;
1253 R__b >> fLast;
1254 // following lines required to repair for a bug in Root version 1.03
1257 if (fLast < fFirst) { fFirst = 0; fLast = 0;}
1258 if (fFirst ==0 && fLast == 0) SetBit(kAxisRange,false);
1259 }
1260 if (R__v > 3) {
1261 R__b >> fTimeDisplay;
1263 } else {
1264 SetTimeFormat();
1265 }
1266 R__b.CheckByteCount(R__s, R__c, TAxis::IsA());
1267 //====end of old versions
1268
1269 } else {
1270 R__b.WriteClassBuffer(TAxis::Class(),this);
1271 }
1272}
1273
1274////////////////////////////////////////////////////////////////////////////////
1275/// Reset first & last bin to the full range
1276
1278{
1279 if (!gPad) {
1280 Warning("TAxis::UnZoom","Cannot UnZoom if gPad does not exist. Did you mean to draw the TAxis first?");
1281 return;
1282 }
1283 gPad->SetView();
1284
1285 //unzoom object owning this axis
1286 SetRange(0,0);
1287 TH1 *hobj1 = (TH1*)GetParent();
1288 if (!strstr(GetName(),"xaxis")) {
1289 if (!hobj1) return;
1290 if (hobj1->GetDimension() == 2) {
1291 if (strstr(GetName(),"zaxis")) {
1292 hobj1->SetMinimum();
1293 hobj1->SetMaximum();
1294 hobj1->ResetBit(TH1::kIsZoomed);
1295 }
1296 return;
1297 }
1298 if (strcmp(hobj1->GetName(),"hframe") == 0 ) {
1299 hobj1->SetMinimum(fXmin);
1300 hobj1->SetMaximum(fXmax);
1301 } else {
1302 if (fXmin==hobj1->GetMinimum() && fXmax==hobj1->GetMaximum()) {
1303 hobj1->SetMinimum(fXmin);
1304 hobj1->SetMaximum(fXmax);
1305 } else {
1306 hobj1->SetMinimum();
1307 hobj1->SetMaximum();
1308 }
1309 hobj1->ResetBit(TH1::kIsZoomed);
1310 }
1311 }
1312 //must unzoom all histograms in the pad
1313 TIter next(gPad->GetListOfPrimitives());
1314 TObject *obj;
1315 while ((obj= next())) {
1316 if (!obj->InheritsFrom(TH1::Class())) continue;
1317 TH1 *hobj = (TH1*)obj;
1318 if (hobj == hobj1) continue;
1319 if (!strstr(GetName(),"xaxis")) {
1320 if (hobj->GetDimension() == 2) {
1321 if (strstr(GetName(),"zaxis")) {
1322 hobj->SetMinimum();
1323 hobj->SetMaximum();
1324 hobj->ResetBit(TH1::kIsZoomed);
1325 } else {
1326 hobj->GetYaxis()->SetRange(0,0);
1327 }
1328 return;
1329 }
1330 if (strcmp(hobj->GetName(),"hframe") == 0 ) {
1331 hobj->SetMinimum(fXmin);
1332 hobj->SetMaximum(fXmax);
1333 } else {
1334 hobj->SetMinimum();
1335 hobj->SetMaximum();
1336 hobj->ResetBit(TH1::kIsZoomed);
1337 }
1338 } else {
1339 hobj->GetXaxis()->SetRange(0,0);
1340 }
1341 }
1342
1343 gPad->UnZoomed();
1344}
1345
1346////////////////////////////////////////////////////////////////////////////////
1347/// Zoom out by a factor of 'factor' (default =2)
1348/// uses previous zoom factor by default
1349/// Keep center defined by 'offset' fixed
1350/// ie. -1 at left of current range, 0 in center, +1 at right
1351
1353{
1354
1355 if (factor <= 0) factor = 2;
1356 Double_t center = (GetFirst()*(1-offset) + GetLast()*(1+offset))/2.;
1357 Int_t first = int(TMath::Floor(center+(GetFirst()-center)*factor + 0.4999999));
1358 Int_t last = int(TMath::Floor(center+(GetLast() -center)*factor + 0.5000001));
1359 if (first==GetFirst() && last==GetLast()) { first--; last++; }
1360 SetRange(first,last);
1361}
#define SafeDelete(p)
Definition RConfig.hxx:533
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t width
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
#define snprintf
Definition civetweb.c:1579
Double_t * fArray
Definition TArrayD.h:30
void Streamer(TBuffer &) override
Stream a TArrayD object.
Definition TArrayD.cxx:148
void Copy(TArrayD &array) const
Definition TArrayD.h:42
void Set(Int_t n) override
Set size of this array to n doubles.
Definition TArrayD.cxx:105
Int_t fN
Definition TArray.h:38
Manages histogram axis attributes.
Definition TAttAxis.h:19
virtual Color_t GetTitleColor() const
Definition TAttAxis.h:47
virtual Color_t GetLabelColor() const
Definition TAttAxis.h:39
Int_t fNdivisions
Number of divisions(10000*n3 + 100*n2 + n1)
Definition TAttAxis.h:21
virtual Int_t GetNdivisions() const
Definition TAttAxis.h:37
virtual Color_t GetAxisColor() const
Definition TAttAxis.h:38
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:279
virtual Style_t GetTitleFont() const
Definition TAttAxis.h:48
virtual Float_t GetLabelOffset() const
Definition TAttAxis.h:41
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
Set color of the line axis and tick marks.
Definition TAttAxis.cxx:141
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition TAttAxis.cxx:184
virtual Style_t GetLabelFont() const
Definition TAttAxis.h:40
virtual void SetTitleFont(Style_t font=62)
Set the title font.
Definition TAttAxis.cxx:308
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition TAttAxis.cxx:172
virtual void SetLabelFont(Style_t font=62)
Set labels' font.
Definition TAttAxis.cxx:161
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title.
Definition TAttAxis.cxx:290
virtual void SaveAttributes(std::ostream &out, const char *name, const char *subname)
Save axis attributes as C++ statement(s) on output stream out.
Definition TAttAxis.cxx:110
virtual void SetTitleColor(Color_t color=1)
Set color of axis title.
Definition TAttAxis.cxx:299
virtual Float_t GetTitleSize() const
Definition TAttAxis.h:45
virtual void Streamer(TBuffer &)
Stream an object of class TAttAxis.
Definition TAttAxis.cxx:317
virtual Float_t GetLabelSize() const
Definition TAttAxis.h:42
virtual Float_t GetTickLength() const
Definition TAttAxis.h:46
virtual void ResetAttAxis(Option_t *option="")
Reset axis attributes.
Definition TAttAxis.cxx:78
virtual Float_t GetTitleOffset() const
Definition TAttAxis.h:44
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length.
Definition TAttAxis.cxx:265
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition TAttAxis.cxx:214
void Copy(TAttAxis &attaxis) const
Copy of the object.
Definition TAttAxis.cxx:60
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
Set color of labels.
Definition TAttAxis.cxx:151
TAxis helper class used to store the modified labels.
Definition TAxisModLab.h:21
Class to manage histogram axis.
Definition TAxis.h:32
virtual void GetCenter(Double_t *center) const
Return an array with the center of all bins.
Definition TAxis.cxx:558
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:1191
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
Definition TAxis.cxx:667
virtual void SetDefaults()
Set axis default values (from TStyle)
Definition TAxis.cxx:871
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition TAxis.cxx:891
Int_t fLast
Last bin to display.
Definition TAxis.h:40
static TClass * Class()
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, const TString &labText="")
Define new text attributes for the label number "labNum".
Definition TAxis.cxx:966
Bool_t IsAlphanumeric() const
Definition TAxis.h:90
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:1352
const char * GetTitle() const override
Returns title of object.
Definition TAxis.h:137
Int_t GetNlabels() const
Return the number of axis labels.
Definition TAxis.cxx:586
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition TAxis.cxx:482
TObject * fParent
! Object owning this axis
Definition TAxis.h:44
Double_t fXmax
Upper edge of last bin.
Definition TAxis.h:37
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to an axis.
Definition TAxis.cxx:260
Bool_t CanExtend() const
Definition TAxis.h:88
TArrayD fXbins
Bin edges array in X.
Definition TAxis.h:38
TAxis()
Default constructor.
Definition TAxis.cxx:50
UInt_t GetTimeOffset()
Return the time offset in GMT.
Definition TAxis.cxx:619
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TAxis.cxx:276
virtual void UnZoom()
Reset first & last bin to the full range.
Definition TAxis.cxx:1277
THashList * fLabels
List of labels.
Definition TAxis.h:45
void SetCanExtend(Bool_t canExtend)
Definition TAxis.h:92
void Copy(TObject &axis) const override
Copy axis structure to another axis.
Definition TAxis.cxx:211
virtual void SetTicks(Option_t *option="+")
Set ticks orientation.
Definition TAxis.cxx:1117
@ kTickMinus
Definition TAxis.h:65
@ kLabelsUp
Definition TAxis.h:75
@ kCenterTitle
Definition TAxis.h:67
@ kRotateTitle
Definition TAxis.h:69
@ kNoExponent
Definition TAxis.h:71
@ kMoreLogLabels
Definition TAxis.h:77
@ kTickPlus
Definition TAxis.h:64
@ kLabelsDown
Definition TAxis.h:74
@ kLabelsHori
Definition TAxis.h:72
@ kAxisRange
Definition TAxis.h:66
@ kDecimals
Definition TAxis.h:63
@ kCenterLabels
Bit 13 is used by TObject.
Definition TAxis.h:68
@ kLabelsVert
Definition TAxis.h:73
Bool_t fTimeDisplay
On/off displaying time values instead of numerics.
Definition TAxis.h:42
TList * fModLabs
List of modified labels.
Definition TAxis.h:46
const char * GetBinLabel(Int_t bin) const
Return label for bin.
Definition TAxis.cxx:444
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition TAxis.cxx:293
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition TAxis.cxx:522
Int_t fNbins
Number of bins.
Definition TAxis.h:35
@ kAlphanumeric
Axis is alphanumeric.
Definition TAxis.h:50
Double_t fXmin
Low edge of first bin.
Definition TAxis.h:36
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition TAxis.cxx:790
Bool_t HasBinWithoutLabel() const
This helper function checks if there is a bin without a label if all bins have labels,...
Definition TAxis.cxx:651
TAxisModLab * FindModLab(Int_t num, Double_t v=0., Double_t eps=0.) const
Search for axis modifier by index or value.
Definition TAxis.cxx:927
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x
Definition TAxis.cxx:422
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:127
void SaveAttributes(std::ostream &out, const char *name, const char *subname) override
Save axis attributes as C++ statement(s) on output stream out.
Definition TAxis.cxx:715
TClass * IsA() const override
Definition TAxis.h:179
Int_t GetLast() const
Return last bin on the axis i.e.
Definition TAxis.cxx:473
virtual void ImportAttributes(const TAxis *axis)
Copy axis attributes to this.
Definition TAxis.cxx:685
virtual const char * GetTimeFormatOnly() const
Return only the time format from the string fTimeFormat.
Definition TAxis.cxx:604
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:505
void SetAlphanumeric(Bool_t alphanumeric=kTRUE)
Set axis alphanumeric.
Definition TAxis.cxx:847
void Streamer(TBuffer &) override
Stream an object of class TAxis.
Definition TAxis.cxx:1224
TAxis & operator=(const TAxis &)
Assignment operator.
Definition TAxis.cxx:113
~TAxis() override
Destructor.
Definition TAxis.cxx:84
void ChangeLabelByValue(Double_t labValue, Double_t labAngle=-1., Double_t labSize=-1., Int_t labAlign=-1, Int_t labColor=-1, Int_t labFont=-1, const TString &labText="")
Define new text attributes for the label value "labValue".
Definition TAxis.cxx:1014
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:1090
virtual const char * GetTimeFormat() const
Definition TAxis.h:134
virtual void GetLowEdge(Double_t *edge) const
Return an array with the low edge of all bins.
Definition TAxis.cxx:567
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition TAxis.cxx:1165
Bool_t CanBeAlphanumeric()
Definition TAxis.h:89
TString fTimeFormat
Date&time format, ex: 09/12/99 12:34:00.
Definition TAxis.h:43
virtual TObject * GetParent() const
Definition TAxis.h:130
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition TAxis.cxx:1061
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition TAxis.cxx:546
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition TAxis.cxx:532
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition TAxis.cxx:462
virtual const char * GetTicks() const
Return the ticks option (see SetTicks)
Definition TAxis.cxx:639
UShort_t fBits2
Second bit status word.
Definition TAxis.h:41
Int_t fFirst
First bin to display.
Definition TAxis.h:39
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Int_t GetEntries() const
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
static TString SavePrimitiveColor(Int_t ci)
Convert color in C++ statement which can be used in SetColor directives Produced statement either inc...
Definition TColor.cxx:2556
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
virtual void GetStats(Double_t *stats) const
fill the array stats from the contents of this histogram The array stats must be correctly dimensione...
Definition TH1.cxx:7879
static TClass * Class()
@ kIsZoomed
Bit set when zooming on Y axis.
Definition TH1.h:407
@ kNstat
Size of statistics data (up to TProfile3D)
Definition TH1.h:422
static void Optimize(Double_t A1, Double_t A2, Int_t nold, Double_t &BinLow, Double_t &BinHigh, Int_t &nbins, Double_t &BWID, Option_t *option="")
Static function to compute reasonable axis limits.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
void Rehash(Int_t newCapacity)
Rehash the hashlist.
TObject * FindObject(const char *name) const override
Find object using its name.
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:600
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
void Copy(TObject &named) const override
Copy this to obj.
Definition TNamed.cxx:93
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
void Streamer(TBuffer &) override
Stream an object of class TObject.
Collectable string class.
Definition TObjString.h:28
void SetString(const char *s)
Definition TObjString.h:45
const char * GetName() const override
Returns name of object.
Definition TObjString.h:38
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition TObject.cxx:475
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1074
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:881
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:543
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1088
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:892
void ResetBit(UInt_t f)
Definition TObject.h:201
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1062
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
void ToLower()
Change string to lower-case.
Definition TString.cxx:1189
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1121
TString & Remove(Ssiz_t pos)
Definition TString.h:694
virtual void Streamer(TBuffer &)
Stream a string object.
Definition TString.cxx:1418
TString & Append(const char *cs)
Definition TString.h:581
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2384
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:660
Double_t GetTimeOffset() const
Definition TStyle.h:271
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
Definition TMath.h:691
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Definition TMathBase.h:329
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122