Logo ROOT  
Reference Guide
draw_subpads.cxx File Reference

Detailed Description

This ROOT 7 example demonstrates how to create a ROOT 7 canvas (RCanvas), divide on sub-pads and draw histograms there.

/*************************************************************************
* Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "ROOT/RCanvas.hxx"
#include "ROOT/RPad.hxx"
#include "ROOT/RStyle.hxx"
#include "TRandom.h"
// macro must be here while cling is not capable to load
// library automatically for outlined function see ROOT-10336
R__LOAD_LIBRARY(libROOTHistDraw)
void draw_subpads()
{
using namespace ROOT::Experimental;
// Create the histogram.
RAxisConfig xaxis(25, 0., 10.);
auto pHist1 = std::make_shared<RH1D>(xaxis);
auto pHist2 = std::make_shared<RH1D>(xaxis);
auto pHist3 = std::make_shared<RH1D>(xaxis);
for (int n=0;n<1000;n++) {
pHist1->Fill(gRandom->Gaus(3., 0.8));
pHist2->Fill(gRandom->Gaus(5., 1.));
pHist3->Fill(gRandom->Gaus(7., 1.2));
}
// Create a canvas to be displayed.
auto canvas = RCanvas::Create("Canvas Title");
// Divide canvas on sub-pads
auto subpads = canvas->Divide(2,2);
subpads[0][0]->Draw(pHist1)->AttrLine().SetColor(RColor::kRed);
subpads[1][0]->Draw(pHist2)->AttrLine().SetColor(RColor::kBlue);
subpads[0][1]->Draw(pHist3)->AttrLine().SetColor(RColor::kGreen);
// Divide pad on sub-sub-pads
auto subsubpads = subpads[1][1]->Divide(2,2);
subsubpads[0][0]->Draw(pHist1)->AttrLine().SetColor(RColor::kBlue);
subsubpads[1][0]->Draw(pHist2)->AttrLine().SetColor(RColor::kGreen);
subsubpads[0][1]->Draw(pHist3)->AttrLine().SetColor(RColor::kRed);
"frame {" // select type frame for RFrame
" gridx: true;" // enable grid drawing
" gridy: true;"
" ticksx: 2;" // enable ticks drawing on both sides
" ticksy: 2;"
" x_labels_size: 0.05;" // below 1 is scaling factor for pad height
" y_labels_size: 20;" // just a font size in pixel
" y_labels_color: green;" // and name labels color
"}");
canvas->UseStyle(style);
canvas->SetSize(1200, 600);
canvas->Show();
RDirectory::Heap().Add("subpads_style", style); // required to keep style alive
}
Date
2018-03-13
Warning
This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
Author
Sergey Linev

Definition in file draw_subpads.cxx.

n
const Int_t n
Definition: legend1.C:16
TRandom::Gaus
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:274
ROOT::Experimental::RAxisConfig
Objects used to configure the different axis types.
Definition: RAxisConfig.hxx:35
RHistDrawable.hxx
ROOT::Experimental::RDirectory::Add
void Add(std::string_view name, const std::shared_ptr< T > &ptr)
Add an existing object (rather a shared_ptr to it) to the RDirectory.
Definition: RDirectory.hxx:175
TRandom.h
ROOT::Experimental::RCanvas::Create
static std::shared_ptr< RCanvas > Create(const std::string &title)
Create new canvas instance.
Definition: RCanvas.cxx:103
RDirectory.hxx
RCanvas.hxx
ROOT::Experimental::RColor::kBlue
static constexpr R__DLLEXPORT RGB_t kBlue
Definition: RColor.hxx:186
RPad.hxx
style
TCanvas * style()
Definition: style.C:1
ROOT::Experimental::RStyle::Parse
static std::shared_ptr< RStyle > Parse(const std::string &css_code)
Parse CSS code and returns std::shared_ptr<RStyle> when successful.
Definition: RStyle.cxx:260
TCanvas::Show
void Show()
Show canvas.
Definition: TCanvas.cxx:2238
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
ROOT::Experimental::RColor::kGreen
static constexpr R__DLLEXPORT RGB_t kGreen
Definition: RColor.hxx:179
ROOT::Experimental::RDirectory::Heap
static RDirectory & Heap()
Dedicated, process-wide RDirectory.
Definition: RFile.cxx:23
ROOT::Experimental
Definition: RDirectory.hxx:30
TPad::Divide
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition: TPad.cxx:1178
RStyle.hxx
R__LOAD_LIBRARY
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:472
ROOT::Experimental::RColor::kRed
static constexpr R__DLLEXPORT RGB_t kRed
Definition: RColor.hxx:191