Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
gr012_polar.py File Reference

Detailed Description

View in nbviewer Open in SWAN
Create and draw a polar graph.

See the TGraphPolar documentation

Since TGraphPolar is a TGraphErrors, it is painted with TGraphPainter options.

With GetPolargram we retrieve the polar axis to format it; see the TGraphPolargram documentation

# Illustrates how to use TGraphPolar
import math
import numpy as np
import ROOT
CPol = ROOT.TCanvas("CPol", "TGraphPolar Examples", 1200, 600)
# Left-side pad. Two graphs without errors
xmin = 0
xmax = math.pi * 2
x = np.array([])
y = np.array([])
xval1 = np.array([])
yval1 = np.array([])
# Graph 1 to be drawn with line and fill
fplot = ROOT.TF1("fplot", "cos(2*x)*cos(20*x)", xmin, xmax)
for ipt in range(1000):
x = np.append(x, ipt * (xmax - xmin) / 1000 + xmin)
y = np.append(y, fplot.Eval(x[ipt]))
grP = ROOT.TGraphPolar(1000, x, y)
grP.Draw("AFL")
# Graph 2 to be drawn superposed over graph 1, with curve and polymarker
for ipt in range(20):
xval1 = np.append(xval1, x[math.floor(1000 / 20 * ipt)])
yval1 = np.append(yval1, y[math.floor(1000 / 20 * ipt)])
grP1 = ROOT.TGraphPolar(20, xval1, yval1)
grP1.Draw("CP")
# To format the polar axis, we retrieve the TGraphPolargram.
# First update the canvas, otherwise GetPolargram returns 0
grP1.GetPolargram().SetRangePolar(-math.pi, math.pi)
grP1.GetPolargram().SetNdivPolar(703)
grP1.GetPolargram().SetToRadian() # tell ROOT that the x and xval1 are in radians
# Right-side pad. One graph with errors
x2 = np.array([])
y2 = np.array([])
ex = np.array([])
ey = np.array([])
for ipt in range(30):
x2 = np.append(x2, x[math.floor(1000 / 30 * ipt)])
y2 = np.append(y2, 1.2 + 0.4 * math.sin(math.pi * 2 * ipt / 30))
ex = np.append(ex, 0.2 + 0.1 * math.cos(2 * math.pi / 30 * ipt))
ey = np.append(ey, 0.2)
# Grah to be drawn with polymarker and errors
grPE = ROOT.TGraphPolar(30, x2, y2, ex, ey)
grPE.Draw("EP")
# To format the polar axis, we retrieve the TGraphPolargram.
# First update the canvas, otherwise GetPolargram returns 0
grPE.GetPolargram().SetTwoPi()
grPE.GetPolargram().SetToRadian() # tell ROOT that the x2 values are in radians
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t SetTextSize
pt SetTextColor(4)
Author
Olivier Couet, Jamie Gooding

Definition in file gr012_polar.py.