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
30using namespace ROOT::Experimental;
31
32void rh2_colz()
33{
34 // Create the histogram.
35 RAxisConfig xaxis("x", 20, 0., 10.);
36 RAxisConfig yaxis("y", 20, 0., 10.);
37 auto pHist = std::make_shared<RH2D>(xaxis, yaxis);
38
39 for (int n=0;n<10000;n++)
40 pHist->Fill({gRandom->Gaus(5.,2.), gRandom->Gaus(5.,2.)});
41
42 // Create a canvas to be displayed.
43 auto canvas = RCanvas::Create("RH2 with color palette");
44
45 auto frame = canvas->AddFrame();
46
47 // should we made special style for frame with palette?
48 frame->margins.right = 0.2_normal;
49
50 frame->gridX = false;
51 frame->gridY = false;
52
53 // draw ticks on both sides
54 frame->ticksX = 2;
55 frame->ticksY = 2;
56
57 // swap frame side where axes are drawn
58 // frame->swapX = true;
59 // frame->swapY = true;
60
61 frame->x.zoomMin = 2;
62 frame->x.zoomMax = 8;
63 frame->y.zoomMin = 2;
64 frame->y.zoomMax = 8;
65
66 auto title = canvas->Draw<RFrameTitle>("2D histogram with color palette");
67 title->margin = 0.01_normal;
68 title->height = 0.09_normal;
69
70 canvas->Draw<RPaletteDrawable>(RPalette::GetPalette(), true);
71
72 auto draw = canvas->Draw(pHist);
73 // draw->line.color = RColor::kLime;
74 // draw->Surf(2); // configure surf4 draw option
75 // draw->Lego(2); // configure lego2 draw option
76 // draw->Contour(); // configure cont draw option
77 // draw->Scatter(); // configure color draw option (default)
78 // draw->Arrow(); // configure arrow draw option
79 draw->Color(); // configure color draw option (default)
80 draw->Text(); // configure text drawing (can be enabled with most 2d options)
81
82 auto stat = canvas->Draw<RHist2StatBox>(pHist, "hist2");
83 stat->fill.color = RColor::kRed;
84 stat->fill.style = RAttrFill::kSolid;
85
86 canvas->SetSize(1000, 700);
87 canvas->Show();
88
89 //canvas->Show("1000x700");
90
91 // canvas->SaveAs("rh2_colz.png");
92}
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