Logo ROOT  
Reference Guide
draw_rh2_colz.cxx File Reference

Detailed Description

This macro generates a small V7 TH2D, fills it with random values and draw it in a V7 canvas, using configured web browser.

/*************************************************************************
* Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "ROOT/RCanvas.hxx"
#include "ROOT/RFrameTitle.hxx"
#include "ROOT/RFrame.hxx"
#include "TRandom.h"
// macro must be here while cling is not capable to load
// library automatically for outlined function see ROOT-10336
R__LOAD_LIBRARY(libROOTHistDraw)
using namespace ROOT::Experimental;
void draw_rh2_colz()
{
// Create the histogram.
RAxisConfig xaxis("x", 20, 0., 10.);
RAxisConfig yaxis("y", 20, 0., 10.);
auto pHist = std::make_shared<RH2D>(xaxis, yaxis);
for (int n=0;n<10000;n++)
pHist->Fill({gRandom->Gaus(5.,2.), gRandom->Gaus(5.,2.)});
// Create a canvas to be displayed.
auto canvas = RCanvas::Create("Canvas Title");
auto frame = canvas->GetOrCreateFrame();
// should we made special style for frame with palette?
frame->AttrMargins().SetRight(0.2_normal);
frame->SetGridX(false).SetGridY(false);
// draw ticks on both sides
frame->SetTicksX(2).SetTicksY(2);
// swap frame side where axes are drawn
// frame->SetSwapX(true).SetSwapY(true);
frame->AttrX().SetZoom(2.,8.);
frame->AttrY().SetZoom(2.,8.);
canvas->Draw<RFrameTitle>("2D histogram with color palette")->SetMargin(0.01_normal).SetHeight(0.09_normal);
auto draw = canvas->Draw(pHist);
// draw->AttrLine().SetColor(RColor::kLime);
// draw->Surf(2); // configure surf4 draw option
// draw->Lego(2); // configure lego2 draw option
// draw->Contour(); // configure cont draw option
// draw->Scatter(); // configure color draw option (default)
// draw->Arrow(); // configure arrow draw option
draw->Color(); // configure color draw option (default)
draw->Text(true); // configure text drawing (can be enabled with most 2d options)
auto stat = canvas->Draw<RHist2StatBox>(pHist, "hist2");
canvas->SetSize(1000, 700);
canvas->Show();
//canvas->Show("1000x700");
// canvas->SaveAs("rh2_colz.png");
}
Date
2020-03-04
Warning
This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
Author
Sergey Linev s.lin.nosp@m.ev@g.nosp@m.si.de

Definition in file draw_rh2_colz.cxx.

n
const Int_t n
Definition: legend1.C:16
ROOT::Experimental::RPalette::GetPalette
static const RPalette & GetPalette(std::string_view name="")
Get a global palette by name.
Definition: RPalette.cxx:143
ROOT::Experimental::RHist2StatBox
Definition: RHistStatBox.hxx:164
RFrame.hxx
ROOT::Experimental::RAxisConfig
Objects used to configure the different axis types.
Definition: RAxisConfig.hxx:35
RHistDrawable.hxx
TRandom.h
ROOT::Experimental::RCanvas::Create
static std::shared_ptr< RCanvas > Create(const std::string &title)
Create new canvas instance.
Definition: RCanvas.cxx:103
RCanvas.hxx
ROOT::Experimental::RAttrFill::SetColor
RAttrFill & SetColor(const RColor &color)
The fill color.
Definition: RAttrFill.hxx:38
ROOT::Experimental::RPave::AttrFill
const RAttrFill & AttrFill() const
Definition: RPave.hxx:63
RPaletteDrawable.hxx
TCanvas::Show
void Show()
Show canvas.
Definition: TCanvas.cxx:2238
RHistStatBox.hxx
TCanvas::Draw
void Draw(Option_t *option="") override
Draw a canvas.
Definition: TCanvas.cxx:843
ROOT::Experimental
Definition: RDirectory.hxx:30
ROOT::Experimental::RPaletteDrawable
A color palette draw near the frame.
Definition: RPaletteDrawable.hxx:32
R__LOAD_LIBRARY
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:472
ROOT::Experimental::RColor::kRed
static constexpr R__DLLEXPORT RGB_t kRed
Definition: RColor.hxx:191