Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
draw.cxx
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_v7
3 ///
4 /// \macro_code
5 ///
6 /// \date 2015-03-22
7 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
8 /// is welcome!
9 /// \author Axel Naumann <axel@cern.ch>
10 
11 /*************************************************************************
12  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
13  * All rights reserved. *
14  * *
15  * For the licensing terms see $ROOTSYS/LICENSE. *
16  * For the list of contributors see $ROOTSYS/README/CREDITS. *
17  *************************************************************************/
18 
19 #include "ROOT/RCanvas.hxx"
20 #include "ROOT/RColor.hxx"
21 #include "ROOT/RHistDrawable.hxx"
22 
23 // macro must be here while cling is not capable to load
24 // library automatically for outlined function see ROOT-10336
25 R__LOAD_LIBRARY(libROOTHistDraw)
26 
27 void draw()
28 {
29  using namespace ROOT::Experimental;
30 
31  // Create the histogram.
32  RAxisConfig xaxis("x", 10, 0., 1.);
33  RAxisConfig yaxis("y", {0., 1., 2., 3., 10.});
34  auto pHist = std::make_shared<RH2D>(xaxis, yaxis);
35 
36  // Fill a few points.
37  pHist->Fill({0.01, 1.02});
38  pHist->Fill({0.54, 3.02});
39  pHist->Fill({0.98, 1.02});
40  pHist->Fill({1.90, 1.02});
41  pHist->Fill({0.75, -0.02});
42 
43  // Create a canvas to be displayed.
44  auto canvas = RCanvas::Create("Canvas Title");
45  auto draw1 = canvas->Draw(pHist);
46  draw1->AttrLine().SetColor(RColor::kRed);
47 
48  auto other = std::make_shared<RH2D>(*pHist);
49  auto draw2 = canvas->Draw(other);
50  draw2->AttrLine().SetColor(RColor::kBlue).SetWidth(12);
51 
52  canvas->Show();
53 }