Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
symlog.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This ROOT 7 example shows how to use symlog scale on RAxis
5/// See discussion on forum https://root-forum.cern.ch/t/symlog-scale-for-plotting/ for more details
6///
7/// \macro_image (rcanvas_js)
8/// \macro_code
9///
10/// \date 2021-05-26
11/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
12/// is welcome!
13/// \author Sergey Linev <s.linev@gsi.de>
14
15/*************************************************************************
16 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
17 * All rights reserved. *
18 * *
19 * For the licensing terms see $ROOTSYS/LICENSE. *
20 * For the list of contributors see $ROOTSYS/README/CREDITS. *
21 *************************************************************************/
22
23#include "ROOT/RCanvas.hxx"
24#include "ROOT/RFrameTitle.hxx"
25#include "ROOT/RFrame.hxx"
26#include "ROOT/RMarker.hxx"
27
28using namespace ROOT::Experimental;
29
30auto symlog_style = RStyle::Parse("frame { margins_left: 0.1; }"
31 "title { margin: 0.01; height: 0.1; }"
32 "marker { onframe: true; clipping: true; }"
33 ".group1 { marker_style: 8; marker_color: blue; }"
34 ".group2 { marker_style: 8; marker_color: orange; }");
35
36void symlog()
37{
38 // Create a canvas to be displayed.
39 auto canvas = RCanvas::Create("Drawing with symlog");
40
41 auto pads = canvas->Divide(1, 3);
42
43 // first pad with linear scales
44 auto frame1 = pads[0][0]->AddFrame();
45 frame1->drawAxes = true;
46 frame1->x.min = -40;
47 frame1->x.max = 1040;
48 frame1->x.title = "x linear";
49 frame1->x.title.SetCenter();
50 frame1->y.log = 10.;
51 frame1->y.min = 1;
52 frame1->y.max = 1e4;
53 frame1->y.title = "y log";
54 frame1->y.title.SetCenter();
55 pads[0][0]->Draw<RFrameTitle>("linear scale");
56
57 // second pad with log scales, negative values missing
58 auto frame2 = pads[0][1]->AddFrame();
59 frame2->drawAxes = true;
60 frame2->x.log = 10.;
61 frame2->x.min = 0.05;
62 frame2->x.max = 1.2e3;
63 frame2->x.title = "x log";
64 frame2->x.title.SetCenter();
65 frame2->y.log = 10.;
66 frame2->y.min = 1;
67 frame2->y.max = 1e4;
68 frame2->y.title = "y log";
69 frame2->y.title.SetCenter();
70 pads[0][1]->Draw<RFrameTitle>("log scale, missing points");
71
72 // third pad with symlog scales
73 auto frame3 = pads[0][2]->AddFrame();
74 frame3->drawAxes = true;
75 // configure symlog scale with 10 for linear range, rest will be logarithmic, including negative
76 frame3->x.symlog = 10.; // boundary inside which linear scale will be used
77 frame3->x.min = -10;
78 frame3->x.max = 1.2e3;
79 frame3->x.title = "x symlog";
80 frame3->x.title.SetCenter();
81 frame3->y.log = 10.;
82 frame3->y.min = 1;
83 frame3->y.max = 1e4;
84 frame3->y.title = "y log";
85 frame3->y.title.SetCenter();
86 pads[0][2]->Draw<RFrameTitle>("symlog scale");
87
88 for (int n=0;n<100;n++) {
89 auto x1 = TMath::Power(10, gRandom->Uniform(1, 2.9));
90 auto y1 = TMath::Power(10, gRandom->Uniform(1, 1.9));
91
92 if (n % 27 == 0) { x1 = 100; y1 *= 100; }
93
95 pads[0][0]->Draw<RMarker>(pm)->SetCssClass("group1");
96 pads[0][1]->Draw<RMarker>(pm)->SetCssClass("group1");
97 pads[0][2]->Draw<RMarker>(pm)->SetCssClass("group1");
98 }
99
100 for (int n=0;n<75;n++) {
101 auto x2 = gRandom->Uniform(-5., 5.);
102 auto y2 = TMath::Power(10, gRandom->Uniform(2.2, 3.7));
103
105 pads[0][0]->Draw<RMarker>(pm)->SetCssClass("group2");
106 pads[0][1]->Draw<RMarker>(pm)->SetCssClass("group2");
107 pads[0][2]->Draw<RMarker>(pm)->SetCssClass("group2");
108 }
109
110 canvas->UseStyle(symlog_style);
111
112 canvas->SetSize(500, 900);
113
114 canvas->Show();
115}
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 TRandom * gRandom
Definition TRandom.h:62
A position (horizontal and vertical) in a RPad.
Definition RPadPos.hxx:28
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition TRandom.cxx:672
const Int_t n
Definition legend1.C:16
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:719