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/// \author Sergey Linev <S.Linev@gsi.de>
14
15#include <ROOT/RCanvas.hxx>
17
18#include "TDatime.h"
19
20void raxis()
21{
22 using namespace ROOT::Experimental;
23
24 // Create a canvas to be displayed.
25 auto canvas = RCanvas::Create("RAxis examples");
26
27 auto x1 = 0.08_normal, w1 = 0.36_normal, x2 = 0.57_normal, w2 = 0.36_normal;
28
29 auto draw0 = canvas->Draw<RAxisDrawable>(RPadPos(0.03_normal,0.1_normal), true, 0.8_normal);
30 draw0->axis.ticks.SetInvert();
31 draw0->axis.ticks.size = 0.02_normal;
32 draw0->axis.title = "vertical";
33
34 auto draw1 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.9_normal), false, w1);
35 draw1->axis.title = "horizontal";
36 draw1->axis.title.SetCenter();
37
38 auto draw2 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.7_normal), false, w1);
39 draw2->axis.ticks.SetBoth();
40 draw2->axis.ticks.size = 0.02_normal;
41 draw2->axis.title = "both side ticks";
42 draw2->axis.title.SetCenter();
43
44 auto draw3 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.5_normal), false, w1);
45 draw3->axis.title = "center labels";
46 draw3->axis.labels.center = true;
47
48 auto draw4 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.3_normal), false, w1);
49 draw4->axis.min = TDatime(2020,11,12,9,0,0).Convert();
50 draw4->axis.max = TDatime(2020,11,12,12,0,0).Convert();
51 draw4->axis.SetTimeDisplay("%d/%m/%y %H:%M");
52 draw4->axis.title = "time display";
53 draw4->axis.labels.size = 0.01;
54 draw4->axis.labels.color = RColor::kRed;
55
56 std::vector<std::string> labels = {"first", "second", "third", "forth", "fifth"};
57 auto draw5 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.1_normal), false, w1);
58 draw5->SetLabels(labels);
59 draw5->axis.ticks.SetInvert();
60 draw5->axis.title = "labels, swap ticks side";
61 draw5->axis.title.SetLeft();
62
63 auto draw6 = canvas->Draw<RAxisDrawable>(RPadPos(0.5_normal,0.9_normal), true, -0.8_normal);
64 draw6->axis.min = 0;
65 draw6->axis.max = 10;
66 draw6->axis.ending.SetArrow();
67 draw6->axis.title = "vertical negative length";
68
69 auto draw7 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.9_normal), false, w2);
70 draw7->axis.min = 1;
71 draw7->axis.max = 100;
72 draw7->axis.log = 10;
73 draw7->axis.title = "log10 scale";
74 draw7->axis.title.SetCenter();
75 draw7->axis.title.font = RAttrFont::kVerdana;
76 draw7->axis.title.color = RColor::kGreen;
77 draw7->axis.ending.SetCircle();
78
79 auto draw8 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.7_normal), false, w2);
80 draw8->axis.min = 0.125;
81 draw8->axis.max = 128;
82 draw8->axis.log = 2;
83 draw8->axis.title = "log2 scale";
84 draw8->axis.title.SetCenter();
85
86 auto draw9 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.5_normal), false, w2);
87 draw9->axis.min = 1;
88 draw9->axis.max = 100;
89 draw9->axis.log = 2.7182;
90 draw9->axis.title = "ln scale";
91 draw9->axis.title.SetCenter();
92
93 auto draw10 = canvas->Draw<RAxisDrawable>(RPadPos(x2+w2, 0.3_normal), false, -w2);
94 draw10->axis.ending.SetArrow();
95 draw10->axis.title = "horizontal negative length";
96 draw10->axis.title.SetCenter();
97
98 auto draw11 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.1_normal), false, w2);
99 draw11->axis.ending.SetArrow();
100 draw11->axis.reverse = true;
101 draw11->axis.title = "horizontal reverse";
102 draw11->axis.title.SetCenter();
103
104 auto draw12 = canvas->Draw<RAxisDrawable>(RPadPos(0.97_normal, 0.1_normal), true, 0.8_normal);
105 draw12->axis.ending.SetArrow();
106 draw12->axis.ending.size = 0.01_normal;
107 draw12->axis.ticks.SetBoth();
108 draw12->axis.ticks.color = RColor::kBlue;
109 draw12->axis.ticks.size = 0.01_normal;
110 draw12->axis.title = "vertical axis with arrow";
111 draw12->axis.title.SetCenter();
112
113 canvas->SetSize(1000, 800);
114
115 // requires Chrome browser, runs in headless mode
116 // canvas->SaveAs("raxis.png");
117
118 canvas->Show();
119}
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
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