Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
gr013_polar2.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_graphs
3## \notebook
4## \preview Create and draw a polar graph with errors and polar axis in radians (PI fractions).
5## See the [TGraphPolar documentation](https:#root.cern/doc/master/classTGraphPolar.html)
6##
7## Since TGraphPolar is a TGraphErrors, it is painted with
8## [TGraphPainter](https:#root.cern/doc/master/classTGraphPainter.html) options.
9##
10## With GetPolargram we retrieve the polar axis to format it see the
11## [TGraphPolargram documentation](https:#root.cern/doc/master/classTGraphPolargram.html)
12##
13## \macro_image
14## \macro_code
15## \author Olivier Couet, Jamie Gooding
16
17import numpy as np
18import ROOT
19
20CPol = ROOT.TCanvas("CPol", "TGraphPolar Example", 500, 500)
21
22theta = np.array([])
23radius = np.array([])
24etheta = np.array([])
25eradius = np.array([])
26
27for i in range(8):
28 theta = np.append(theta, (i + 1) * (np.pi / 4.0))
29 radius = np.append(radius, (i + 1) * 0.05)
30 etheta = np.append(etheta, np.pi / 8.0)
31 eradius = np.append(eradius, 0.05)
32
33grP1 = ROOT.TGraphPolar(8, theta, radius, etheta, eradius)
35
41# Draw with polymarker and errors
42grP1.Draw("PE")
43
44# To format the polar axis, we retrieve the TGraphPolargram.
45# First update the canvas, otherwise GetPolargram returns 0
48 grP1.GetPolargram().SetToRadian() # tell ROOT that the theta values are in radians
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.