-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFanPlot.py
65 lines (51 loc) · 2.12 KB
/
FanPlot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import patches
from matplotlib.dates import num2date
class FanPlot:
def __init__(self, nrange=75, nbeam=16, r0=180, dr=45, dtheta=3.24):
# Set member variables
self.nrange = nrange
self.nbeam = nbeam
self.r0 = r0
self.dr = dr
self.dtheta = dtheta
# Initial angle (from X, polar coordinates) for beam 0
self.theta0 = (90 - dtheta * nbeam / 2)
self._open_figure()
def _open_figure(self):
# Create axis
self.fig = plt.figure(figsize=(12,9))
self.ax = self.fig.add_subplot(111, polar=True)
# Set up ticks and labels
self.r_ticks = range(self.r0, self.r0 + (self.nrange+1) * self.dr, self.dr)
self.theta_ticks = [self.theta0 + self.dtheta * b for b in range(self.nbeam+1)]
rlabels = [""] * len(self.r_ticks)
for i in range(0, len(rlabels), 5):
rlabels[i] = i
plt.rgrids(self.r_ticks, rlabels)
plt.thetagrids(self.theta_ticks, range(self.nbeam))
def _scale_plot(self):
# Scale min-max
self.ax.set_thetamin(self.theta_ticks[0])
self.ax.set_thetamax(self.theta_ticks[-1])
self.ax.set_rmin(0)
self.ax.set_rmax(self.r_ticks[-1])
def plot(self, beams, gates, color="blue"):
for beam, gate in zip(beams, gates):
theta = (self.theta0 + beam * self.dtheta) * np.pi / 180 # radians
r = (self.r0 + gate * self.dr) # km
width = self.dtheta * np.pi / 180 # radians
height = self.dr # km
x1, x2 = theta, theta + width
y1, y2 = r, r + height
x = x1, x2, x2, x1
y = y1, y1, y2, y2
self.ax.fill(x, y, color=color)
self._scale_plot()
if __name__ == '__main__':
fanplot = FanPlot()
fanplot.plot([4, 5, 6], [70, 69, 71], "red")
fanplot.plot([7, 8, 9], [70, 69, 71], "blue")
fanplot.plot([7, 8, 9], [30, 30, 30], "yellow")
plt.show()