Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
draw_subpads.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_v7
3//
4/// This ROOT 7 example demonstrates how to create a ROOT 7 canvas (RCanvas),
5/// divide on subpads and draw histograms there
6///
7/// \macro_code
8///
9/// \date 2018-03-13
10/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
11/// \author Sergey Linev
12
13/*************************************************************************
14 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
15 * All rights reserved. *
16 * *
17 * For the licensing terms see $ROOTSYS/LICENSE. *
18 * For the list of contributors see $ROOTSYS/README/CREDITS. *
19 *************************************************************************/
20
22#include "ROOT/RCanvas.hxx"
23#include "ROOT/RPad.hxx"
24#include "ROOT/RStyle.hxx"
25#include "ROOT/RDirectory.hxx"
26#include "TRandom.h"
27
28// macro must be here while cling is not capable to load
29// library automatically for outlined function see ROOT-10336
30R__LOAD_LIBRARY(libROOTHistDraw)
31
32void draw_subpads()
33{
34 using namespace ROOT::Experimental;
35
36 // Create the histogram.
37 RAxisConfig xaxis(25, 0., 10.);
38 auto pHist1 = std::make_shared<RH1D>(xaxis);
39 auto pHist2 = std::make_shared<RH1D>(xaxis);
40 auto pHist3 = std::make_shared<RH1D>(xaxis);
41
42
43 for (int n=0;n<1000;n++) {
44 pHist1->Fill(gRandom->Gaus(3., 0.8));
45 pHist2->Fill(gRandom->Gaus(5., 1.));
46 pHist3->Fill(gRandom->Gaus(7., 1.2));
47 }
48
49 // Create a canvas to be displayed.
50 auto canvas = RCanvas::Create("Canvas Title");
51
52 // Divide canvas on sub-pads
53
54 auto subpads = canvas->Divide(2,2);
55
56 subpads[0][0]->Draw(pHist1)->AttrLine().SetColor(RColor::kRed);
57 subpads[1][0]->Draw(pHist2)->AttrLine().SetColor(RColor::kBlue);
58 subpads[0][1]->Draw(pHist3)->AttrLine().SetColor(RColor::kGreen);
59
60 // Divide pad on sub-sub-pads
61 auto subsubpads = subpads[1][1]->Divide(2,2);
62
63 subsubpads[0][0]->Draw(pHist1)->AttrLine().SetColor(RColor::kBlue);
64 subsubpads[1][0]->Draw(pHist2)->AttrLine().SetColor(RColor::kGreen);
65 subsubpads[0][1]->Draw(pHist3)->AttrLine().SetColor(RColor::kRed);
66
67 auto style = RStyle::Parse(
68 "frame {" // select type frame for RFrame
69 " gridx: true;" // enable grid drawing
70 " gridy: true;"
71 " ticksx: 2;" // enable ticks drawing on both sides
72 " ticksy: 2;"
73 " x_labels_size: 0.05;" // below 1 is scaling factor for pad height
74 " y_labels_size: 20;" // just a font size in pixel
75 " y_labels_color_name: green;" // and name labels color
76 "}");
77 canvas->UseStyle(style);
78 RDirectory::Heap().Add("style", style); // required to keep style alive
79
80 canvas->SetSize(1200, 600);
81 canvas->Show();
82}
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:472
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
Objects used to configure the different axis types.
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
const Int_t n
Definition legend1.C:16
TCanvas * style()
Definition style.C:1