Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
transparentpad.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gl
3/// This macro demonstrates semi-transparent pads.
4/// Requires OpenGL or Web-based canvas.
5///
6/// \macro_image(nobatch)
7/// \macro_code
8///
9/// \authors Timur Pocheptsov, Sergey Linev
10
11// Includes for ACLiC (cling does not need them).
12#include "TCanvas.h"
13#include "TStyle.h"
14#include "TError.h"
15#include "TColor.h"
16#include "TH1F.h"
17
18void transparentpad(bool gl = true)
19{
21
22 // 1. Create canvas and check if it support transparent colors
23 auto c1 = new TCanvas("transparentpad", "transparent pad demo", 10, 10, 900, 500);
24 if (!c1->UseGL() && !c1->IsWeb())
25 ::Warning("transparentpad",
26 "You can see the transparency ONLY in a pdf or png output (\"File\"->\"Save As\" ->...)\n"
27 "To have transparency in a canvas graphics, you need either OpenGL or Web rendering enabled");
28
29 // 2. Some arbitrary histograms.
30 auto h1 = new TH1F("TH1F 1", "TH1F 1", 100, -1.5, 1.5);
31 h1->FillRandom("gaus");
32
33 auto h2 = new TH1F("TH1F 2", "TH1F 2", 100, -1.5, 0.);
34 h2->FillRandom("gaus");
35
36 auto h3 = new TH1F("TH1F 3", "TH1F 3", 100, 0.5, 2.);
37 h3->FillRandom("landau");
38
39 // 3. Now overlapping transparent pads.
40 auto pad1 = new TPad("transparent pad 1", "transparent pad 1", 0.1, 0.1, 0.7, 0.7);
41 pad1->SetFillColor(TColor::GetColor((Float_t)1., 0.2, 0.2, 0.25)); // transparent pink, here's the magic!
42 c1->cd();
43 pad1->Draw();
44 pad1->cd();
45 h1->Draw("lego2");
46
47 auto pad2 = new TPad("transparent pad 2", "transparent pad 2", 0.2, 0.2, 0.8, 0.8);
48 pad2->SetFillColor(TColor::GetColor((Float_t)0.2, 1., 0.2, 0.25)); // transparent green, here's the magic!
49 c1->cd();
50 pad2->Draw();
51 pad2->cd();
52 h2->Draw();
53
54 auto pad3 = new TPad("transparent pad 3", "transparent pad 3", 0.3, 0.3, 0.9, 0.9);
55 pad3->SetFillColor(TColor::GetColor((Float_t)0.2, 1., 1., 0.15)); // transparent blue, here's the magic!
56 c1->cd();
57 pad3->Draw();
58 pad3->cd();
59 h3->Draw();
60}
float Float_t
Definition RtypesCore.h:57
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
The Canvas class.
Definition TCanvas.h:23
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1921
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:623
virtual void FillRandom(TF1 *f1, Int_t ntimes=5000, TRandom *rng=nullptr)
Definition TH1.cxx:3530
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3068
The most important graphics class in the ROOT system.
Definition TPad.h:28
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition TStyle.h:341
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5