Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rh2_colz.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
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_image (rcanvas_js)
8/// \macro_code
9///
10/// \date 2020-03-04
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-2020, 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/RFrameTitle.hxx"
26#include "ROOT/RHistStatBox.hxx"
27#include "ROOT/RFrame.hxx"
28#include "TRandom.h"
29
30// macro must be here while cling is not capable to load
31// library automatically for outlined function see ROOT-10336
32R__LOAD_LIBRARY(libROOTHistDraw)
33
34using namespace ROOT::Experimental;
35
36void rh2_colz()
37{
38 // Create the histogram.
39 RAxisConfig xaxis("x", 20, 0., 10.);
40 RAxisConfig yaxis("y", 20, 0., 10.);
41 auto pHist = std::make_shared<RH2D>(xaxis, yaxis);
42
43 for (int n=0;n<10000;n++)
44 pHist->Fill({gRandom->Gaus(5.,2.), gRandom->Gaus(5.,2.)});
45
46 // Create a canvas to be displayed.
47 auto canvas = RCanvas::Create("RH2 with color palette");
48
49 auto frame = canvas->AddFrame();
50
51 // should we made special style for frame with palette?
52 frame->margins.right = 0.2_normal;
53
54 frame->gridX = false;
55 frame->gridY = false;
56
57 // draw ticks on both sides
58 frame->ticksX = 2;
59 frame->ticksY = 2;
60
61 // swap frame side where axes are drawn
62 // frame->swapX = true;
63 // frame->swapY = true;
64
65 frame->x.zoomMin = 2;
66 frame->x.zoomMax = 8;
67 frame->y.zoomMin = 2;
68 frame->y.zoomMax = 8;
69
70 auto title = canvas->Draw<RFrameTitle>("2D histogram with color palette");
71 title->margin = 0.01_normal;
72 title->height = 0.09_normal;
73
74 canvas->Draw<RPaletteDrawable>(RPalette::GetPalette(), true);
75
76 auto draw = canvas->Draw(pHist);
77 // draw->line.color = RColor::kLime;
78 // draw->Surf(2); // configure surf4 draw option
79 // draw->Lego(2); // configure lego2 draw option
80 // draw->Contour(); // configure cont draw option
81 // draw->Scatter(); // configure color draw option (default)
82 // draw->Arrow(); // configure arrow draw option
83 draw->Color(); // configure color draw option (default)
84 draw->Text(); // configure text drawing (can be enabled with most 2d options)
85
86 auto stat = canvas->Draw<RHist2StatBox>(pHist, "hist2");
87 stat->fill.color = RColor::kRed;
88 stat->fill.style = RAttrFill::kSolid;
89
90 canvas->SetSize(1000, 700);
91 canvas->Show();
92
93 //canvas->Show("1000x700");
94
95 // canvas->SaveAs("rh2_colz.png");
96}
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:491
RAttrValue< RColor > color
! fill color
Definition RAttrFill.hxx:43
Objects used to configure the different axis types.
A color palette draw near the frame.
RAttrFill fill
! fill attributes
Definition RPave.hxx:48
const Int_t n
Definition legend1.C:16