Logo ROOT   6.14/05
Reference Guide
draw_subpads.cxx
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_v7
3 ///
4 /// \macro_code
5 ///
6 /// \date 2018-03-13
7 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
8 /// \author Sergey Linev
9 
10 /*************************************************************************
11  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
12  * All rights reserved. *
13  * *
14  * For the licensing terms see $ROOTSYS/LICENSE. *
15  * For the list of contributors see $ROOTSYS/README/CREDITS. *
16  *************************************************************************/
17 
18 #include "ROOT/THist.hxx"
19 #include "ROOT/TCanvas.hxx"
20 #include "ROOT/TPad.hxx"
21 
22 void draw_subpads() {
23  using namespace ROOT;
24 
25  // Create the histogram.
26  Experimental::TAxisConfig xaxis(10, 0., 10.);
27  auto pHist1 = std::make_shared<Experimental::TH1D>(xaxis);
28  auto pHist2 = std::make_shared<Experimental::TH1D>(xaxis);
29  auto pHist3 = std::make_shared<Experimental::TH1D>(xaxis);
30 
31  // Fill a few points.
32  pHist1->Fill(1);
33  pHist1->Fill(2);
34  pHist1->Fill(2);
35  pHist1->Fill(3);
36 
37  pHist2->Fill(5);
38  pHist2->Fill(6);
39  pHist2->Fill(6);
40  pHist2->Fill(7);
41 
42  pHist3->Fill(4);
43  pHist3->Fill(5);
44  pHist3->Fill(5);
45  pHist3->Fill(6);
46 
47  // Create a canvas to be displayed.
48  auto canvas = Experimental::TCanvas::Create("Canvas Title");
49 
50  // Divide canvas on sub-pads
51 
52  auto subpads = canvas->Divide(2,2);
53 
54  subpads[0][0]->Draw(pHist1)->SetLineColor(Experimental::TColor::kRed);
55  subpads[1][0]->Draw(pHist2)->SetLineColor(Experimental::TColor::kBlue);
56  subpads[0][1]->Draw(pHist3)->SetLineColor(Experimental::TColor::kGreen);
57 
58  // Divide pad on sub-sub-pads
59  auto subsubpads = subpads[1][1]->Divide(2,2);
60 
61  subsubpads[0][0]->Draw(pHist1)->SetLineColor(Experimental::TColor::kBlue);
62  subsubpads[1][0]->Draw(pHist2)->SetLineColor(Experimental::TColor::kGreen);
63  subsubpads[0][1]->Draw(pHist3)->SetLineColor(Experimental::TColor::kRed);
64 
65  canvas->Show();
66 }
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Definition: Rtypes.h:59
Definition: Rtypes.h:59
Objects used to configure the different axis types.
Definition: TAxis.hxx:300
Definition: Rtypes.h:59
static std::shared_ptr< TCanvas > Create(const std::string &title)
Definition: TCanvas.cxx:74