Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
gr019_scatter2d.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3/// \notebook
4/// \preview Draw a 2D scatter plot.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Olivier Couet
10
11void gr019_scatter2d()
12{
13 auto canvas = new TCanvas("canvas","canvas");
14 canvas->SetRightMargin(0.14);
15 gStyle->SetPalette(kBird, 0, 0.6); // define a transparent palette
16
17 const int n = 50;
18 double x1[n];
19 double y1[n];
20 double z1[n];
21 double c1[n];
22 double s1[n];
23 double x2[n];
24 double y2[n];
25 double z2[n];
26 double c2[n];
27 double s2[n];
28
29 // Define four random data set
30 auto r = new TRandom();
31 for (int i=0; i<n; i++) {
32 x1[i] = 100*r->Rndm(i);
33 y1[i] = 200*r->Rndm(i);
34 z1[i] = 10*r->Rndm(i);
35 c1[i] = 10000*r->Rndm(i);
36 s1[i] = 10000*r->Rndm(i);
37 x2[i] = 100*r->Rndm(i);
38 y2[i] = 200*r->Rndm(i);
39 z2[i] = 10*r->Rndm(i);
40 c2[i] = 5000*r->Rndm(i);
41 s2[i] = 100*r->Rndm(i);
42 }
43 c1[0] = 1;
44
45 auto scatter1 = new TScatter2D(n, x1, y1, z1, c1, s1);
46 scatter1->SetTitle("Scatter plot title;X title;Y title;Z title;C title");
47 scatter1->SetMarkerStyle(20);
48
49 auto scatter2 = new TScatter2D(n, x2, y2, z2, c2, s2);
50 scatter2->SetMarkerStyle(21);
51
52 canvas->SetLogx();
53 scatter1->Draw("logc");
54 scatter2->Draw("SAME");
55}
ROOT::R::TRInterface & r
Definition Object.C:4
#define s1(x)
Definition RSha256.hxx:91
@ kBird
Definition TColor.h:121
externTStyle * 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
return c1
Definition legend1.C:41
const Int_t n
Definition legend1.C:16
return c2
Definition legend2.C:14