forked from ApolloAuto/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstitem.py
76 lines (65 loc) · 2.55 KB
/
stitem.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
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
"""S T Item"""
import numpy as np
from matplotlib import lines
from matplotlib.patches import Polygon
class Stitem(object):
"""Specific item to plot"""
def __init__(self, ax, title, xlabel, ylabel):
self.ax = ax
self.title = title
self.ax.set_title(title)
self.ax.set_xlabel(xlabel, fontsize=10)
self.ax.set_ylabel(ylabel, fontsize=10)
self.planningavailable = False
def reset(self):
"""Reset"""
self.ax.cla()
self.ax.set_xlim([-0.1, 0.1])
self.ax.set_ylim([-0.1, 0.1])
def new_planning(self, time, values, polygons_t, polygons_s):
"""new planning"""
max_time = max(time) + 1
max_value = max(values) + 1
if self.planningavailable == False:
self.ax.set_xlim([0, max_time])
self.ax.set_ylim([0, max_value])
self.ymax = max_value
self.tmax = max_time
self.current_line = lines.Line2D(time, values, color='red', lw=1.5)
self.ax.add_line(self.current_line)
else:
self.current_line.set_data(time, values)
_, xmax = self.ax.get_xlim()
if max_time > xmax:
self.ax.set_xlim([0, max_time])
_, ymax = self.ax.get_ylim()
if max_value > ymax:
self.ax.set_ylim([0, max_value])
self.ax.patches = []
for i in range(len(polygons_s)):
points = np.vstack((polygons_t[i], polygons_s[i])).T
polygon = Polygon(points)
self.ax.add_patch(polygon)
self.planningavailable = True
def draw_lines(self):
"""plot lines"""
for polygon in self.ax.patches:
self.ax.draw_artist(polygon)
for line in self.ax.lines:
self.ax.draw_artist(line)