Logo ROOT  
Reference Guide
subpads.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This ROOT 7 example demonstrates how to create a ROOT 7 canvas (RCanvas),
5/// divide on sub-sub pads and draw histograms there
6///
7/// \macro_image (rcanvas_js)
8/// \macro_code
9///
10/// \date 2018-03-13
11/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
12/// \author Sergey Linev <s.linev@gsi.de>
13
14/*************************************************************************
15 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
16 * All rights reserved. *
17 * *
18 * For the licensing terms see $ROOTSYS/LICENSE. *
19 * For the list of contributors see $ROOTSYS/README/CREDITS. *
20 *************************************************************************/
21
23#include "ROOT/RCanvas.hxx"
24#include "ROOT/RPad.hxx"
25#include "ROOT/RStyle.hxx"
26#include "ROOT/RDirectory.hxx"
27#include "TRandom.h"
28
29// macro must be here while cling is not capable to load
30// library automatically for outlined function see ROOT-10336
31R__LOAD_LIBRARY(libROOTHistDraw)
32
33void subpads()
34{
35 using namespace ROOT::Experimental;
36
37 // Create the histogram.
38 RAxisConfig xaxis(25, 0., 10.);
39 auto pHist1 = std::make_shared<RH1D>(xaxis);
40 auto pHist2 = std::make_shared<RH1D>(xaxis);
41 auto pHist3 = std::make_shared<RH1D>(xaxis);
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("Sub-sub pads example");
51
52 // Divide canvas on sub-pads
53
54 auto subpads = canvas->Divide(2,2);
55
56 subpads[0][0]->Draw(pHist1)->line.color = RColor::kRed;
57 subpads[1][0]->Draw(pHist2)->line.color = RColor::kBlue;
58 subpads[0][1]->Draw(pHist3)->line.color = RColor::kGreen;
59
60 // Divide sub-pad on sub-sub-pads
61 auto subsubpads = subpads[1][1]->Divide(2,2);
62
63 subsubpads[0][0]->Draw(pHist1)->line.color = RColor::kBlue;
64 subsubpads[1][0]->Draw(pHist2)->line.color = RColor::kGreen;
65 subsubpads[0][1]->Draw(pHist3)->line.color = 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: green;" // and name labels color
76 "}");
77 canvas->UseStyle(style);
78
79 canvas->SetSize(1200, 600);
80 canvas->Show();
81
82 RDirectory::Heap().Add("subpads_style", style); // required to keep style alive
83}
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:472
@ kRed
Definition: Rtypes.h:66
@ kGreen
Definition: Rtypes.h:66
@ kBlue
Definition: Rtypes.h:66
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
Objects used to configure the different axis types.
Definition: RAxisConfig.hxx:35
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
RModel Parse(std::string filename)
Parser function for translatng Keras .h5 model into a RModel object.
TCanvas * style()
Definition: style.C:1