Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
draw_rh2_colz.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_v7
3///
4/// This macro generates a small V7 TH2D, fills it with random values and
5/// draw it in a V7 canvas, using configured web browser
6///
7/// \macro_code
8///
9/// \date 2020-03-04
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-2020, 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
22#include "ROOT/RCanvas.hxx"
23#include "ROOT/RFrameTitle.hxx"
25#include "ROOT/RHistStatBox.hxx"
26#include "ROOT/RFrame.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
33using namespace ROOT::Experimental;
34
35void draw_rh2_colz()
36{
37 // Create the histogram.
38 RAxisConfig xaxis("x", 20, 0., 10.);
39 RAxisConfig yaxis("y", 20, 0., 10.);
40 auto pHist = std::make_shared<RH2D>(xaxis, yaxis);
41
42 for (int n=0;n<10000;n++)
43 pHist->Fill({gRandom->Gaus(5.,2.), gRandom->Gaus(5.,2.)});
44
45 // Create a canvas to be displayed.
46 auto canvas = RCanvas::Create("Canvas Title");
47
48 auto frame = canvas->GetOrCreateFrame();
49
50 // should we made special style for frame with palette?
51 frame->Margins().SetRight(0.2_normal);
52
53 frame->SetGridX(false).SetGridY(false);
54
55 // draw ticks on both sides
56 frame->SetTicksX(2).SetTicksY(2);
57
58 // swap frame side where axes are drawn
59 // frame->SetSwapX(true).SetSwapY(true);
60
61 frame->AttrX().SetZoom(2.,8.);
62
63 frame->AttrY().SetZoom(2.,8.);
64
65 canvas->Draw<RFrameTitle>("2D histogram with color palette")->SetMargin(0.01_normal).SetHeight(0.09_normal);
66
67 canvas->Draw<RPaletteDrawable>(RPalette::GetPalette(), true);
68
69 auto draw = canvas->Draw(pHist);
70 // draw->AttrLine().SetColor(RColor::kLime);
71 // draw->Surf(2); // configure surf4 draw option
72 // draw->Lego(2); // configure lego2 draw option
73 // draw->Contour(); // configure cont draw option
74 // draw->Scatter(); // configure color draw option (default)
75 // draw->Arrow(); // configure arrow draw option
76 draw->Color(); // configure color draw option (default)
77 draw->Text(true); // configure text drawing (can be enabled with most 2d options)
78
79 auto stat = canvas->Draw<RHist2StatBox>(pHist, "hist2");
80 stat->AttrFill().SetColor(RColor::kRed);
81
82 canvas->SetSize(1000, 700);
83 canvas->Show();
84
85 //canvas->Show("1000x700");
86
87 // canvas->SaveAs("rh2_colz.png");
88}
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:472
RAttrFill & SetColor(const RColor &color)
The fill color.
Definition RAttrFill.hxx:39
Objects used to configure the different axis types.
A color palette draw near the frame.
RAttrFill & AttrFill()
Definition RPave.hxx:67
const Int_t n
Definition legend1.C:16