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