-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.py
More file actions
138 lines (104 loc) · 3.69 KB
/
plotter.py
File metadata and controls
138 lines (104 loc) · 3.69 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
from LED import LED
class Plotter(object):
fig, ax = plt.subplots() #create figure and axes
leds = []
w = 0.0
h = 0.0
def __init__(self, leds, w=100, h=100):
self.leds = leds
self.w = w
self.h = h
self.ax.set_aspect('equal')
self.ax.set_xlim(0, float(self.w))
self.ax.set_ylim(0, float(self.w))
self.x = [led.x for led in self.leds]
self.y = [led.y for led in self.leds]
self.area = [led.area for led in self.leds]
self.scatter = self.ax.scatter(self.x, self.y, s=self.area)
plt.show()
return
def update_plot(self, colors):
self.scatter.set_facecolors(colors)
# self.ax.scatter(self.x, self.y, c=colors, s=self.area)
plt.draw()
return
# def plot_animate(self, i):
# colors1 = np.random.rand(181)
# # self.line.set_ydata(c=colors1) # update the data
# x1 = [led.x for led in self.leds]
# y1 = [led.y for led in self.leds]
# area1 = [led.area for led in self.leds]
# self.line, = self.ax.scatter(x1, y1, c=colors1, s=area1)
# return self.line,
#
#
# # Init only required for blitting to give a clean slate.
# def init(self):
# self.ax.set_aspect('equal')
# self.ax.set_xlim(0, float(self.w))
# self.ax.set_ylim(0, float(self.w))
# x1 = [led.x for led in self.leds]
# y1 = [led.y for led in self.leds]
# area1 = [led.area for led in self.leds]
# colors1 = np.random.rand(181)
# self.line, = self.ax.scatter(x1, y1, c=colors1, s=area1)
#
#
# def start(self):
# self.ani = animation.FuncAnimation(self.fig, self.plot_animate, np.arange(1, 200), init_func=self.init,
# interval=25, blit=True)
# plt.show()
def plot_cartesian(leds, colors, w=100, h=100):
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
x1 = [led.x for led in leds]
y1 = [led.y for led in leds]
colors = np.random.rand(N)
colors1 = np.random.rand(181)
area = np.pi * (15 * np.random.rand(N))**2 # 0 to 15 point radiuses
area1 = [led.area for led in leds]
fig, ax = plt.subplots() #create figure and axes
ax.set_aspect('equal')
ax.set_xlim(0, float(w))
ax.set_ylim(0, float(w))
ax.scatter(x1, y1, c=colors1, s=area1)
plt.show()
return
def plot_polar(leds, colors, w=100, h=100):
fig, ax = plt.subplots() #create figure and axes
ax.set_aspect('equal')
ax.set_xlim(0, float(w))
ax.set_ylim(0, float(w))
N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
r1 = [led.rho for led in leds]
theta1 = [led.phi for led in leds]
area = 200 * r**2 * np.random.rand(N)
colors = theta
ax = plt.subplot(111, projection='polar')
#c = plt.scatter(theta, r, c=colors, s=area, cmap=plt.cm.hsv)
c = plt.scatter(theta1, r1, cmap=plt.cm.hsv)
c.set_alpha(0.75)
plt.show()
return
def plot_animate():
x = np.arange(6)
y = np.arange(5)
z = x * y[:, np.newaxis]
for i in range(5):
if i == 0:
p = plt.imshow(z)
fig = plt.gcf()
plt.clim() # clamp the color limits
plt.title("Boring slide show")
else:
z = z + 2
p.set_data(z)
print("step", i)
plt.pause(0.5)