Logo ROOT  
Reference Guide
draw_axes.cxx File Reference

Detailed Description

This ROOT7 example demonstrates how to create a RCanvas and draw several RAxis objects with different options.

#include <ROOT/RCanvas.hxx>
#include "TDatime.h"
// macro must be here while cling is not capable to load
// library automatically for outlined function see ROOT-10336
R__LOAD_LIBRARY(libROOTGpadv7)
void draw_axes()
{
using namespace ROOT::Experimental;
// Create a canvas to be displayed.
auto canvas = RCanvas::Create("RAxis examples");
auto x1 = 0.08_normal, w1 = 0.36_normal, x2 = 0.57_normal, w2 = 0.36_normal;
auto draw0 = canvas->Draw<RAxisDrawable>(RPadPos(0.03_normal,0.1_normal), true, 0.8_normal);
draw0->AttrAxis().SetTitle("vertical").SetTicksInvert().SetTicksSize(0.02_normal);
auto draw1 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.9_normal), false, w1);
draw1->AttrAxis().SetTitle("horizontal").SetTitleCenter();
auto draw2 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.7_normal), false, w1);
draw2->AttrAxis().SetTicksBoth().SetTicksSize(0.02_normal)
.SetTitle("both side ticks").SetTitleCenter();
auto draw3 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.5_normal), false, w1);
draw3->AttrAxis().SetTitle("center labels").SetLabelsCenter();
auto draw4 = canvas->Draw<RAxisDrawable>(RPadPos(x1, 0.3_normal), false, w1);
draw4->SetMinMax(TDatime(2020,11,12,9,0,0).Convert(), TDatime(2020,11,12,12,0,0).Convert())
.AttrAxis().SetTimeDisplay("%d/%m/%y %H:%M").SetTitle("time display").LabelsAttr().SetSize(0.01).SetColor(RColor::kRed);
std::vector<std::string> labels = {"first", "second", "third", "forth", "fifth"};
auto draw5 = canvas->Draw<RAxisLabelsDrawable>(RPadPos(x1, 0.1_normal), false, w1);
draw5->SetLabels(labels).AttrAxis().SetTitle("labels, swap ticks side").SetTitleLeft().SetTicksInvert();
auto draw6 = canvas->Draw<RAxisDrawable>(RPadPos(0.5_normal,0.9_normal), true, -0.8_normal);
draw6->SetMinMax(0, 10).AttrAxis().SetTitle("vertical negative length").SetEndingArrow();
auto draw7 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.9_normal), false, w2);
auto draw8 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.7_normal), false, w2);
draw8->SetMinMax(0.125, 128).AttrAxis().SetLog(2).SetTitle("log2 scale").SetTitleCenter();
auto draw9 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.5_normal), false, w2);
draw9->SetMinMax(1, 100).AttrAxis().SetLog(2.7182).SetTitle("ln scale").SetTitleCenter();
auto draw10 = canvas->Draw<RAxisDrawable>(RPadPos(x2+w2, 0.3_normal), false, -w2);
draw10->AttrAxis().SetTitle("horizontal negative length").SetTitleCenter().SetEndingArrow();
auto draw11 = canvas->Draw<RAxisDrawable>(RPadPos(x2, 0.1_normal), false, w2);
draw11->AttrAxis().SetReverse().SetTitle("horizontal reverse").SetTitleCenter().SetEndingArrow();
auto draw12 = canvas->Draw<RAxisDrawable>(RPadPos(0.97_normal, 0.1_normal), true, 0.8_normal);
draw12->AttrAxis().SetTitle("vertical axis with arrow").SetTitleCenter()
.SetEndingArrow().SetEndingSize(0.01_normal);
canvas->SetSize(1000, 800);
// requires Chrome browser, runs in headless mode
// canvas->SaveAs("axes.png");
canvas->Show();
}
Date
2020-11-03
Warning
This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
Authors
Sergey Linev S.Lin.nosp@m.ev@g.nosp@m.si.de

Definition in file draw_axes.cxx.

ROOT::Experimental::RAttrAxis::SetEndingArrow
RAttrAxis & SetEndingArrow()
Definition: RAttrAxis.hxx:123
ROOT::Experimental::RAttrAxis::SetTitleCenter
RAttrAxis & SetTitleCenter()
Definition: RAttrAxis.hxx:161
ROOT::Experimental::RAxisLabelsDrawable
Labels axis drawing.
Definition: RAxisDrawable.hxx:99
ROOT::Experimental::RAttrAxis::SetLog
RAttrAxis & SetLog(double base=10)
Definition: RAttrAxis.hxx:79
ROOT::Experimental::RAttrAxis::SetTitle
RAttrAxis & SetTitle(const std::string &title)
Definition: RAttrAxis.hxx:156
TDatime.h
ROOT::Experimental::RAxisDrawable::SetMinMax
RAxisDrawable & SetMinMax(double min, double max)
Definition: RAxisDrawable.hxx:83
ROOT::Experimental::RAttrAxis::SetTicksSize
RAttrAxis & SetTicksSize(const RPadLength &sz)
Definition: RAttrAxis.hxx:127
ROOT::Experimental::RCanvas::Create
static std::shared_ptr< RCanvas > Create(const std::string &title)
Create new canvas instance.
Definition: RCanvas.cxx:103
ROOT::Experimental::RAxisDrawableBase::AttrAxis
const RAttrAxis & AttrAxis() const
Definition: RAxisDrawable.hxx:58
RCanvas.hxx
ROOT::Experimental::RColor::kBlue
static constexpr R__DLLEXPORT RGB_t kBlue
Definition: RColor.hxx:186
ROOT::Experimental::RAxisDrawable
Plain axis drawing.
Definition: RAxisDrawable.hxx:73
x1
static const double x1[5]
Definition: RooGaussKronrodIntegrator1D.cxx:346
ROOT::Experimental::RAttrAxis::SetEndingSize
RAttrAxis & SetEndingSize(const RPadLength &sz)
Definition: RAttrAxis.hxx:119
ROOT::Experimental::RAttrAxis::TitleAttr
RAttrText & TitleAttr()
Definition: RAttrAxis.hxx:154
ROOT::Experimental::RAxisLabelsDrawable::SetLabels
RAxisLabelsDrawable & SetLabels(const std::vector< std::string > &lbls)
Definition: RAxisDrawable.hxx:109
ROOT::Experimental::RAttrAxis::SetTitleLeft
RAttrAxis & SetTitleLeft()
Definition: RAttrAxis.hxx:160
ROOT::Experimental::RAttrText::SetColor
RAttrText & SetColor(const RColor &color)
The color of the text.
Definition: RAttrText.hxx:51
TCanvas::Show
void Show()
Show canvas.
Definition: TCanvas.cxx:2238
RAxisDrawable.hxx
ROOT::Experimental::RColor::kGreen
static constexpr R__DLLEXPORT RGB_t kGreen
Definition: RColor.hxx:179
ROOT::Experimental::RAttrAxis::SetLabelsCenter
RAttrAxis & SetLabelsCenter(bool on=true)
Definition: RAttrAxis.hxx:149
ROOT::Experimental::RAttrAxis::SetReverse
RAttrAxis & SetReverse(bool on=true)
Definition: RAttrAxis.hxx:98
x2
static const double x2[5]
Definition: RooGaussKronrodIntegrator1D.cxx:364
TDatime
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:37
TCanvas::Draw
void Draw(Option_t *option="") override
Draw a canvas.
Definition: TCanvas.cxx:843
TDatime::Convert
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:182
ROOT::Experimental
Definition: RDirectory.hxx:30
ROOT::Experimental::RPadPos
A position (horizontal and vertical) in a RPad.
Definition: RPadPos.hxx:28
ROOT::Experimental::RAttrAxis::SetTicksColor
RAttrAxis & SetTicksColor(const RColor &color)
Definition: RAttrAxis.hxx:136
R__LOAD_LIBRARY
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:472
ROOT::Experimental::RAttrAxis::SetTicksBoth
RAttrAxis & SetTicksBoth()
Definition: RAttrAxis.hxx:133
ROOT::Experimental::RAttrAxis::SetTicksInvert
RAttrAxis & SetTicksInvert()
Definition: RAttrAxis.hxx:132
ROOT::Experimental::RAttrText::SetFont
RAttrText & SetFont(int font)
Set text font by id as usually handled in the ROOT, set number between 1 and 15.
Definition: RAttrText.hxx:55
ROOT::Experimental::RColor::kRed
static constexpr R__DLLEXPORT RGB_t kRed
Definition: RColor.hxx:191