Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
draw_axes.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_v7
3///
4/// This ROOT7 example demonstrates how to create a RCanvas and
5/// draw several RAxis objects with different options.
6///
7/// \macro_image (axes.png)
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 draw_axes()
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->AttrAxis().SetTitle("vertical").SetTicksInvert().SetTicksSize(0.02_normal);
36
37 auto draw1 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.9_normal), false, w1);
38 draw1->AttrAxis().SetTitle("horizontal").SetTitleCenter();
39
40 auto draw2 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.7_normal), false, w1);
41 draw2->AttrAxis().SetTicksBoth().SetTicksSize(0.02_normal)
42 .SetTitle("both side ticks").SetTitleCenter();
43
44 auto draw3 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.5_normal), false, w1);
45 draw3->AttrAxis().SetTitle("center labels").SetLabelsCenter();
46
47 auto draw4 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.3_normal), false, w1);
48 draw4->SetMinMax(TDatime(2020,11,12,9,0,0).Convert(), TDatime(2020,11,12,12,0,0).Convert())
49 .AttrAxis().SetTimeDisplay("%d/%m/%y %H:%M").SetTitle("time display").LabelsAttr().SetSize(0.01).SetColor(RColor::kRed);
50
51 std::vector<std::string> labels = {"first", "second", "third", "forth", "fifth"};
52 auto draw5 = canvas->Draw<RAxisLabelsDrawable>(RPadPos(x1, 0.1_normal), false, w1);
53 draw5->SetLabels(labels).AttrAxis().SetTitle("labels, swap ticks side").SetTitleLeft().SetTicksInvert();
54
55 auto draw6 = canvas->Draw<RAxisDrawable>(RPadPos(0.5_normal,0.9_normal), true, -0.8_normal);
56 draw6->SetMinMax(0, 10).AttrAxis().SetTitle("vertical negative length").SetEndingArrow();
57
58 auto draw7 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.9_normal), false, w2);
59 draw7->SetMinMax(1, 100).AttrAxis().SetLog(10).SetTitle("log10 scale").SetTitleCenter().TitleAttr().SetFont(12).SetColor(RColor::kGreen);
60
61 auto draw8 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.7_normal), false, w2);
62 draw8->SetMinMax(0.125, 128).AttrAxis().SetLog(2).SetTitle("log2 scale").SetTitleCenter();
63
64 auto draw9 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.5_normal), false, w2);
65 draw9->SetMinMax(1, 100).AttrAxis().SetLog(2.7182).SetTitle("ln scale").SetTitleCenter();
66
67 auto draw10 = canvas->Draw<RAxisDrawable>(RPadPos(x2+w2, 0.3_normal), false, -w2);
68 draw10->AttrAxis().SetTitle("horizontal negative length").SetTitleCenter().SetEndingArrow();
69
70 auto draw11 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.1_normal), false, w2);
71 draw11->AttrAxis().SetReverse().SetTitle("horizontal reverse").SetTitleCenter().SetEndingArrow();
72
73 auto draw12 = canvas->Draw<RAxisDrawable>(RPadPos(0.97_normal, 0.1_normal), true, 0.8_normal);
74 draw12->AttrAxis().SetTitle("vertical axis with arrow").SetTitleCenter()
75 .SetTicksBoth().SetTicksSize(0.01_normal).SetTicksColor(RColor::kBlue)
76 .SetEndingArrow().SetEndingSize(0.01_normal);
77
78 canvas->SetSize(1000, 800);
79
80 // requires Chrome browser, runs in headless mode
81 // canvas->SaveAs("axes.png");
82
83 canvas->Show();
84}
static const double x2[5]
static const double x1[5]
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:472
RAttrAxis & SetLog(double base=10)
Definition RAttrAxis.hxx:64
RAttrAxis & SetEndingSize(const RPadLength &sz)
Definition RAttrAxis.hxx:89
RAttrAxis & SetTicksSize(const RPadLength &sz)
Definition RAttrAxis.hxx:97
RAttrAxis & SetTitle(const std::string &title)
RAttrAxis & SetTicksColor(const RColor &color)
RAttrAxis & SetReverse(bool on=true)
Definition RAttrAxis.hxx:67
RAttrAxis & SetLabelsCenter(bool on=true)
RAttrText & SetColor(const RColor &color)
The color of the text.
RAttrText & SetFont(int font)
Set text font by id as usually handled in the ROOT, set number between 1 and 15.
Definition RAttrText.hxx:52
RAxisDrawable & SetMinMax(double min, double max)
RAxisLabelsDrawable & 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