Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 x[n];
20 double y[n];
21 double c[n];
22 double s[n];
23
24 // Define four random data sets
25 auto r = new TRandom();
26 for (int i=0; i<n; i++) {
27 x[i] = 100*r->Rndm(i);
28 y[i] = 200*r->Rndm(i);
29 c[i] = 300*r->Rndm(i);
30 s[i] = 400*r->Rndm(i);
31 }
32
33 auto scatter = new TScatter(n, x, y, c, s);
34 scatter->SetMarkerStyle(20);
35 scatter->SetTitle("Scatter plot title;X title;Y title;Z title");
36 scatter->GetXaxis()->SetRangeUser(20.,90.);
37 scatter->GetYaxis()->SetRangeUser(55.,90.);
38 scatter->GetZaxis()->SetRangeUser(10.,200.);
39 scatter->Draw("A");
40}
#define c(i)
Definition RSha256.hxx:101
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kBird
Definition TColor.h:119
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
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:1890
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16