Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rh2.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This macro generates RH2D and draw it with different options in RCanvas
5///
6/// \macro_image (rcanvas_js)
7/// \macro_code
8///
9/// \date 2020-06-25
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 <s.linev@gsi.de>
12
13/*************************************************************************
14 * Copyright (C) 1995-2021, 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
21#include "ROOT/RHist.hxx"
23#include "ROOT/RFrameTitle.hxx"
24#include "ROOT/RCanvas.hxx"
25#include "ROOT/RPad.hxx"
26#include "TRandom.h"
27
28using namespace ROOT::Experimental;
29
30void rh2()
31{
32 // Create the histogram.
33 RAxisConfig xaxis("x", 20, 0., 10.);
34 RAxisConfig yaxis("y", 20, 0., 10.);
35 auto pHist = std::make_shared<RH2D>(xaxis, yaxis);
36
37 for (int n=0;n<10000;n++)
38 pHist->Fill({gRandom->Gaus(5.,2.), gRandom->Gaus(5.,2.)});
39
40 // Create a canvas to be displayed.
41 auto canvas = RCanvas::Create("RH2 drawing options");
42
43 // Divide canvas on 2x3 sub-pads to show different draw options
44 auto subpads = canvas->Divide(2,3);
45
46 // default draw option
47 subpads[0][0]->Draw<RFrameTitle>("Color() draw option (default)");
48 subpads[0][0]->Draw(pHist);
49
50 // contour draw options
51 subpads[1][0]->Draw<RFrameTitle>("Contour() draw option");
52 subpads[1][0]->Draw(pHist)->Contour();
53
54 // text draw options
55 subpads[0][1]->Draw<RFrameTitle>("Text() draw option");
56 subpads[0][1]->Draw(pHist)->Text().text.color = RColor::kBlue;
57
58 // arrow draw options
59 subpads[1][1]->Draw<RFrameTitle>("Arrow() draw option");
60 auto draw11 = subpads[1][1]->Draw(pHist);
61 draw11->Arrow();
62 draw11->line.color = RColor::kRed;
63
64 // lego draw options
65 subpads[0][2]->Draw<RFrameTitle>("Lego() draw option");
66 subpads[0][2]->Draw(pHist)->Lego(2);
67
68 // surf draw option
69 subpads[1][2]->Draw<RFrameTitle>("Surf() draw option");
70 subpads[1][2]->Draw(pHist)->Surf(2);
71
72 canvas->SetSize(1000, 700);
73 canvas->Show();
74}
Objects used to configure the different axis types.
const Int_t n
Definition legend1.C:16