Logo ROOT  
Reference Guide
rh1_twoscales.cxx File Reference

Detailed Description

This macro generates two RH1D, fills them and draw in RCanvas.

Second histogram uses enables "secondy" attribute to draw separate Y axis on right side

* Copyright (C) 1995-2021, 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/RHist.hxx"
#include "ROOT/RFrameTitle.hxx"
#include "ROOT/RCanvas.hxx"
#include "ROOT/RPad.hxx"
#include "TRandom.h"
// macro must be here while cling is not capable to load
// library automatically for outlined function see ROOT-10336
using namespace ROOT::Experimental;
void rh1_twoscales()
// Create the histogram.
RAxisConfig xaxis(25, 0., 10.);
auto pHist1 = std::make_shared<RH1D>(xaxis);
auto pHist2 = std::make_shared<RH1D>(xaxis);
for (int n=0;n<1000;n++)
for (int n=0;n<3000;n++)
// Create a canvas to be displayed.
auto canvas = RCanvas::Create("RH1 with two Y scales");
// histograms colors
auto col1 = RColor::kRed, col2 = RColor::kBlue;
// default draw option
canvas->Draw<RFrameTitle>("Two independent Y axes for histograms");
auto draw1 = canvas->Draw(pHist1);
draw1->line.color = col1;
draw1->line.width = 2;
auto draw2 = canvas->Draw(pHist2);
draw2->secondy = true;
draw2->line.color = col2;
draw2->line.width = 4;
canvas->GetFrame()->y.ticks.color = col1;
canvas->GetFrame()->y2.ticks.color = col2;
canvas->SetSize(800, 600);
Definition: Rtypes.h:472
@ kRed
Definition: Rtypes.h:66
@ kBlue
Definition: Rtypes.h:66
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:274
const Int_t n
Definition: legend1.C:16
This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
Sergey Linev s.lin.nosp@m.ev@g.nosp@m.si.de

Definition in file rh1_twoscales.cxx.