MCPcopy
hub / github.com/PiLiDAR/PiLiDAR / plot_2D

Class plot_2D

lib/matplotlib_2D.py:6–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5
6class plot_2D:
7 def __init__(self, pause=0.005, plotrange=1000, s=1):
8 self.x_list = np.array([])
9 self.y_list = np.array([])
10 self.color_list = np.array([])
11
12 self.fig = plt.figure(figsize=(8, 8))
13 self.fig.patch.set_facecolor('black') # set the figure's background color to black
14 self.ax = self.fig.add_subplot(111)
15 self.plotrange = plotrange
16 self.ax.set_ylim([-self.plotrange, self.plotrange])
17 self.ax.set_xlim([-self.plotrange, self.plotrange])
18 self.ax.set_title('LiDAR', fontsize=18)
19 self.ax.set_facecolor('black')
20 # self.ax.xaxis.grid(True, color='yellow', linestyle='dashed')
21 # self.ax.yaxis.grid(True, color='yellow', linestyle='dashed')
22 # self.ax.set_xticks(np.arange(-self.plotrange, self.plotrange+1, 100))
23 # self.ax.set_yticks(np.arange(-self.plotrange, self.plotrange+1, 100))
24 self.ani = self.__initialize_animation__()
25 self.pause = pause
26 self.s = s
27
28 def __initialize_animation__(self):
29 return animation.FuncAnimation(self.fig, self.animate, init_func=self.init, frames=1, interval=1, blit=True)
30
31 def __gray2rgb__(self, luminances):
32 return np.column_stack((luminances, luminances, luminances))
33
34 def init(self):
35 return self.ax,
36
37 def animate(self, i):
38 line = getattr(self, 'line', None)
39 if line is not None:
40 line.remove()
41
42 self.line = self.ax.scatter(self.x_list, self.y_list, c=self.color_list/255, s=self.s)
43 return self.line,
44
45 # def update_lists(self, x_list, y_list, luminance_list):
46 # self.x_list = np.asarray(x_list)
47 # self.y_list = np.asarray(y_list)
48 # self.color_list = self.__gray2rgb__(np.asarray(luminance_list))
49 # plt.pause(self.pause)
50
51 def update(self, points_2d): # points_2d: np.array([[x, y, luminance], ...])
52 line = getattr(self, 'line', None)
53 if line is not None:
54 line.remove()
55
56 self.x_list = points_2d[:, 0]
57 self.y_list = points_2d[:, 1]
58 self.color_list = self.__gray2rgb__(points_2d[:, 2])
59
60 self.line = self.ax.scatter(self.x_list, self.y_list, c=self.color_list/255, s=self.s)
61
62 # # Set the plot range based on the maximum absolute value in x_list and y_list
63 # self.plotrange = max(max(abs(self.x_list)), max(abs(self.y_list)))

Callers 2

lidar_driver.pyFile · 0.90
matplotlib_2D.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected