Logo ROOT  
Reference Guide
rlegend.cxx File Reference

Detailed Description

This macro generates two TH1D objects and build RLegend In addition use of auto colors are shown.

* Copyright (C) 1995-2019, 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/RLegend.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 rlegend()
// Create the histograms.
RAxisConfig xaxis(25, 0., 10.);
auto pHist = std::make_shared<RH1D>(xaxis);
auto pHist2 = std::make_shared<RH1D>(xaxis);
for (int n=0;n<1000;n++) {
// Create a canvas to be displayed.
auto canvas = RCanvas::Create("RLegend example");
// add palette to canvas, it will not be seen on the canvas but used for colors
canvas->Draw<RPaletteDrawable>(RPalette({{0., RColor::kWhite}, {.3, RColor::kRed}, {.7, RColor::kBlue}, {1., RColor::kBlack}}), false);
// draw first histogram
auto draw1 = canvas->Draw(pHist);
draw1->line.width = 2.f;
draw1->line.color = .3f; // should be red color
// draw second histogram
auto draw2 = canvas->Draw(pHist2);
draw2->line.width = 4.f;
draw2->line.color = .7f; // should be blue color
auto legend = canvas->Draw<RLegend>("Legend title");
legend->fill.color = RColor(0, 0, 120, 25);
legend->fill.style = RAttrFill::k3019;
legend->border.color = RColor::kRed;
legend->border.width = 2;
legend->AddEntry(draw1, "histo1", "l");
legend->AddEntry(draw2, "histo2", "l");
// add custom entry, showing line, fill and marker attributes
auto custom = legend->AddEntry("test", "lfm");
custom->line.color = RColor::kGreen;
custom->line.width = 5.;
custom->line.style = RAttrLine::kSolid;
custom->fill.color = RColor::kBlue;
custom->fill.style = RAttrFill::k3004;
custom->marker.color = RColor::kRed;
custom->marker.size = 0.03;
custom->marker.style = RAttrMarker::kOpenCross;
canvas->SetSize(1000, 700);
Definition: Rtypes.h:472
@ kRed
Definition: Rtypes.h:66
@ kBlack
Definition: Rtypes.h:65
@ kGreen
Definition: Rtypes.h:66
@ kWhite
Definition: Rtypes.h:65
@ kBlue
Definition: Rtypes.h:66
@ kSolid
Definition: TAttLine.h:48
@ kOpenCross
Definition: TAttMarker.h:53
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 rlegend.cxx.