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