Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
gr006_scatter.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3/// \notebook
4/// \preview Draw a scatter plot for 4 variables, mapped to: x, y, marker colour and marker size.
5///
6/// TScatter is available since ROOT v.6.30. See the [TScatter documentation](https://root.cern/doc/master/classTScatter.html)
7///
8/// \macro_image
9/// \macro_code
10/// \author Olivier Couet
11
12void gr006_scatter()
13{
14 auto canvas = new TCanvas();
15 canvas->SetRightMargin(0.14);
16 gStyle->SetPalette(kBird, 0, 0.6); // define a transparent palette
17
18 const int n = 175;
19 double x1[n];
20 double y1[n];
21 double c1[n];
22 double s1[n];
23 double x2[n];
24 double y2[n];
25 double c2[n];
26 double s2[n];
27
28 // Define four random data sets
29 auto r = new TRandom();
30 for (int i=0; i<n; i++) {
31 x1[i] = 100*r->Rndm(i);
32 y1[i] = 200*r->Rndm(i);
33 c1[i] = 300*r->Rndm(i);
34 s1[i] = 400*r->Rndm(i);
35 x2[i] = 100*r->Rndm(i);
36 y2[i] = 200*r->Rndm(i);
37 c2[i] = 100*r->Rndm(i);
38 s2[i] = 200*r->Rndm(i);
39 }
40
41 auto scatter1 = new TScatter(n, x1, y1, c1, s1);
42 scatter1->SetMarkerStyle(20);
43 scatter1->SetTitle("Scatter plot title;X title;Y title;Z title");
44 scatter1->GetXaxis()->SetRangeUser(20.,90.);
45 scatter1->GetYaxis()->SetRangeUser(55.,90.);
46 scatter1->GetZaxis()->SetRangeUser(10.,200.);
47 // an alternative way to zoom the Z-axis:
48 // scatter->GetHistogram()->SetMinimum(10);
49 // scatter->GetHistogram()->SetMaximum(200);
50 scatter1->Draw("A");
51
52 auto scatter2 = new TScatter(n, x2, y2, c2, s2);
53 scatter2->SetMarkerStyle(21);
54 scatter2->Draw();
55}
#define s1(x)
Definition RSha256.hxx:91
@ kBird
Definition TColor.h:121
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
The Canvas class.
Definition TCanvas.h:23
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
A TScatter is able to draw four variables scatter plot on a single plot.
Definition TScatter.h:32
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1889
return c1
Definition legend1.C:41
const Int_t n
Definition legend1.C:16
return c2
Definition legend2.C:14