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", "You can see the transparency ONLY in a pdf or png output (\"File\"->\"Save As\" ->...)\n"
26 "To have transparency in a canvas graphics, you need either OpenGL or Web rendering enabled");
27
28 // 2. Some arbitrary histograms.
29 auto h1 = new TH1F("TH1F 1", "TH1F 1", 100, -1.5, 1.5);
30 h1->FillRandom("gaus");
31
32 auto h2 = new TH1F("TH1F 2", "TH1F 2", 100, -1.5, 0.);
33 h2->FillRandom("gaus");
34
35 auto h3 = new TH1F("TH1F 3", "TH1F 3", 100, 0.5, 2.);
36 h3->FillRandom("landau");
37
38 // 3. Now overlapping transparent pads.
39 auto pad1 = new TPad("transparent pad 1", "transparent pad 1", 0.1, 0.1, 0.7, 0.7);
40 pad1->SetFillColor(TColor::GetColor((Float_t) 1., 0.2, 0.2, 0.25)); // transparent pink, here's the magic!
41 c1->cd();
42 pad1->Draw();
43 pad1->cd();
44 h1->Draw("lego2");
45
46 auto pad2 = new TPad("transparent pad 2", "transparent pad 2", 0.2, 0.2, 0.8, 0.8);
47 pad2->SetFillColor(TColor::GetColor((Float_t) 0.2, 1., 0.2, 0.25)); // transparent green, here's the magic!
48 c1->cd();
49 pad2->Draw();
50 pad2->cd();
51 h2->Draw();
52
53 auto pad3 = new TPad("transparent pad 3", "transparent pad 3", 0.3, 0.3, 0.9, 0.9);
54 pad3->SetFillColor(TColor::GetColor((Float_t) 0.2, 1., 1., 0.15)); // transparent blue, here's the magic!
55 c1->cd();
56 pad3->Draw();
57 pad3->cd();
58 h3->Draw();
59}
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:433
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:1839
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:621
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3519
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
The most important graphics class in the ROOT system.
Definition TPad.h:28
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition TStyle.h:339
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5