Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
raxis.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This ROOT7 example demonstrates how to create a RCanvas and
5/// draw several RAxis objects with different options.
6///
7/// \macro_image (rcanvas_js)
8/// \macro_code
9///
10/// \date 2020-11-03
11/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
12/// is welcome!
13/// \authors Sergey Linev <S.Linev@gsi.de>
14
15#include <ROOT/RCanvas.hxx>
17
18#include "TDatime.h"
19
20// macro must be here while cling is not capable to load
21// library automatically for outlined function see ROOT-10336
22R__LOAD_LIBRARY(libROOTGpadv7)
23
24
25void raxis()
26{
27 using namespace ROOT::Experimental;
28
29 // Create a canvas to be displayed.
30 auto canvas = RCanvas::Create("RAxis examples");
31
32 auto x1 = 0.08_normal, w1 = 0.36_normal, x2 = 0.57_normal, w2 = 0.36_normal;
33
34 auto draw0 = canvas->Draw<RAxisDrawable>(RPadPos(0.03_normal,0.1_normal), true, 0.8_normal);
35 draw0->axis.ticks.SetInvert();
36 draw0->axis.ticks.size = 0.02_normal;
37 draw0->axis.title = "vertical";
38
39 auto draw1 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.9_normal), false, w1);
40 draw1->axis.title = "horizontal";
41 draw1->axis.title.SetCenter();
42
43 auto draw2 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.7_normal), false, w1);
44 draw2->axis.ticks.SetBoth();
45 draw2->axis.ticks.size = 0.02_normal;
46 draw2->axis.title = "both side ticks";
47 draw2->axis.title.SetCenter();
48
49 auto draw3 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.5_normal), false, w1);
50 draw3->axis.title = "center labels";
51 draw3->axis.labels.center = true;
52
53 auto draw4 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.3_normal), false, w1);
54 draw4->axis.min = TDatime(2020,11,12,9,0,0).Convert();
55 draw4->axis.max = TDatime(2020,11,12,12,0,0).Convert();
56 draw4->axis.SetTimeDisplay("%d/%m/%y %H:%M");
57 draw4->axis.title = "time display";
58 draw4->axis.labels.size = 0.01;
59 draw4->axis.labels.color = RColor::kRed;
60
61 std::vector<std::string> labels = {"first", "second", "third", "forth", "fifth"};
62 auto draw5 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.1_normal), false, w1);
63 draw5->SetLabels(labels);
64 draw5->axis.ticks.SetInvert();
65 draw5->axis.title = "labels, swap ticks side";
66 draw5->axis.title.SetLeft();
67
68 auto draw6 = canvas->Draw<RAxisDrawable>(RPadPos(0.5_normal,0.9_normal), true, -0.8_normal);
69 draw6->axis.min = 0;
70 draw6->axis.max = 10;
71 draw6->axis.ending.SetArrow();
72 draw6->axis.title = "vertical negative length";
73
74 auto draw7 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.9_normal), false, w2);
75 draw7->axis.min = 1;
76 draw7->axis.max = 100;
77 draw7->axis.log = 10;
78 draw7->axis.title = "log10 scale";
79 draw7->axis.title.SetCenter();
80 draw7->axis.title.font = RAttrFont::kVerdana;
81 draw7->axis.title.color = RColor::kGreen;
82 draw7->axis.ending.SetCircle();
83
84 auto draw8 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.7_normal), false, w2);
85 draw8->axis.min = 0.125;
86 draw8->axis.max = 128;
87 draw8->axis.log = 2;
88 draw8->axis.title = "log2 scale";
89 draw8->axis.title.SetCenter();
90
91 auto draw9 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.5_normal), false, w2);
92 draw9->axis.min = 1;
93 draw9->axis.max = 100;
94 draw9->axis.log = 2.7182;
95 draw9->axis.title = "ln scale";
96 draw9->axis.title.SetCenter();
97
98 auto draw10 = canvas->Draw<RAxisDrawable>(RPadPos(x2+w2, 0.3_normal), false, -w2);
99 draw10->axis.ending.SetArrow();
100 draw10->axis.title = "horizontal negative length";
101 draw10->axis.title.SetCenter();
102
103 auto draw11 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.1_normal), false, w2);
104 draw11->axis.ending.SetArrow();
105 draw11->axis.reverse = true;
106 draw11->axis.title = "horizontal reverse";
107 draw11->axis.title.SetCenter();
108
109 auto draw12 = canvas->Draw<RAxisDrawable>(RPadPos(0.97_normal, 0.1_normal), true, 0.8_normal);
110 draw12->axis.ending.SetArrow();
111 draw12->axis.ending.size = 0.01_normal;
112 draw12->axis.ticks.SetBoth();
113 draw12->axis.ticks.color = RColor::kBlue;
114 draw12->axis.ticks.size = 0.01_normal;
115 draw12->axis.title = "vertical axis with arrow";
116 draw12->axis.title.SetCenter();
117
118 canvas->SetSize(1000, 800);
119
120 // requires Chrome browser, runs in headless mode
121 // canvas->SaveAs("raxis.png");
122
123 canvas->Show();
124}
static const double x2[5]
static const double x1[5]
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:472
RAttrAxisTicks ticks
! ticks attributes
RAttrAxisTitle title
! title attributes
RAttrLineEnding ending
! ending attributes
RAttrValue< double > min
! axis min
RAttrAxis axis
! axis attributes
RAxisDrawable & SetLabels(const std::vector< std::string > &lbls)
A position (horizontal and vertical) in a RPad.
Definition RPadPos.hxx:28
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