Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TRandom.h"
27
28void subpads()
29{
30 using namespace ROOT::Experimental;
31
32 // Create the histogram.
33 RAxisConfig xaxis(25, 0., 10.);
34 auto pHist1 = std::make_shared<RH1D>(xaxis);
35 auto pHist2 = std::make_shared<RH1D>(xaxis);
36 auto pHist3 = std::make_shared<RH1D>(xaxis);
37
38 for (int n = 0; n < 1000; n++) {
39 pHist1->Fill(gRandom->Gaus(3., 0.8));
40 pHist2->Fill(gRandom->Gaus(5., 1.));
41 pHist3->Fill(gRandom->Gaus(7., 1.2));
42 }
43
44 // Create a canvas to be displayed.
45 auto canvas = RCanvas::Create("Sub-sub pads example");
46
47 // Divide canvas on sub-pads
48
49 auto subpads = canvas->Divide(2,2);
50
51 subpads[0][0]->Draw(pHist1)->line.color = RColor::kRed;
52 subpads[1][0]->Draw(pHist2)->line.color = RColor::kBlue;
53 subpads[0][1]->Draw(pHist3)->line.color = RColor::kGreen;
54
55 // Divide sub-pad on sub-sub-pads
56 auto subsubpads = subpads[1][1]->Divide(2,2);
57
58 subsubpads[0][0]->Draw(pHist1)->line.color = RColor::kBlue;
59 subsubpads[1][0]->Draw(pHist2)->line.color = RColor::kGreen;
60 subsubpads[0][1]->Draw(pHist3)->line.color = RColor::kRed;
61
62 auto style = RStyle::Parse(
63 "frame {" // select type frame for RFrame
64 " gridX: true;" // enable grid drawing
65 " gridY: true;"
66 " ticksX: 2;" // enable ticks drawing on both sides
67 " ticksY: 2;"
68 " x_labels_size: 0.05;" // below 1 is scaling factor for pad height
69 " y_labels_size: 20;" // just a font size in pixel
70 " y_labels_color: green;" // and name labels color
71 "}");
72 canvas->UseStyle(style);
73
74 canvas->SetSize(1200, 600);
75 canvas->Show();
76
77 canvas->ClearOnClose(style);
78}
Option_t Option_t style
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:275
const Int_t n
Definition legend1.C:16