-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize_f.py
132 lines (113 loc) · 3.68 KB
/
visualize_f.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
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
import plotly.graph_objs as go
from PIL import Image
def save_figure_to_html(fig, filename):
fig.write_html(filename)
def visualize_trajectory(trajectory, floor_plan_filename, width_meter, height_meter, title=None, mode='lines + markers + text', show=False):
fig = go.Figure()
# add trajectory
size_list = [6] * trajectory.shape[0]
size_list[0] = 10
size_list[-1] = 10
color_list = ['rgba(4, 174, 4, 0.5)'] * trajectory.shape[0]
color_list[0] = 'rgba(12, 5, 235, 1)'
color_list[-1] = 'rgba(235, 5, 5, 1)'
position_count = {}
text_list = []
for i in range(trajectory.shape[0]):
if str(trajectory[i]) in position_count:
position_count[str(trajectory[i])] += 1
else:
position_count[str(trajectory[i])] = 0
text_list.append(' ' * position_count[str(trajectory[i])] + f'{i}')
text_list[0] = 'Start Point: 0'
text_list[-1] = f'End Point: {trajectory.shape[0] - 1}'
fig.add_trace(
go.Scattergl(
x=trajectory[:, 0],
y=trajectory[:, 1],
mode=mode,
marker=dict(size=size_list, color=color_list),
line=dict(shape='linear', color='rgb(100, 10, 100)', width=2, dash='dot'),
text=text_list,
textposition="top center",
name='trajectory',
))
# add floor plan
floor_plan = Image.open(floor_plan_filename)
fig.update_layout(images=[
go.layout.Image(
source=floor_plan,
xref="x",
yref="y",
x=0,
y=height_meter,
sizex=width_meter,
sizey=height_meter,
sizing="contain",
opacity=1,
layer="below",
)
])
# configure
fig.update_xaxes(autorange=False, range=[0, width_meter])
fig.update_yaxes(autorange=False, range=[0, height_meter], scaleanchor="x", scaleratio=1)
fig.update_layout(
title=go.layout.Title(
text=title or "No title.",
xref="paper",
x=0,
),
autosize=True,
width=900,
height=200 + 900 * height_meter / width_meter,
template="plotly_white",
)
if show:
fig.show()
return fig
def visualize_heatmap(position, value, floor_plan_filename, width_meter, height_meter, colorbar_title="colorbar", title=None, show=False):
fig = go.Figure()
# add heat map
fig.add_trace(
go.Scatter(x=position[:, 0],
y=position[:, 1],
mode='markers',
marker=dict(size=7,
color=value,
colorbar=dict(title=colorbar_title),
colorscale="Rainbow"),
text=value,
name=title))
# add floor plan
floor_plan = Image.open(floor_plan_filename)
fig.update_layout(images=[
go.layout.Image(
source=floor_plan,
xref="x",
yref="y",
x=0,
y=height_meter,
sizex=width_meter,
sizey=height_meter,
sizing="contain",
opacity=1,
layer="below",
)
])
# configure
fig.update_xaxes(autorange=False, range=[0, width_meter])
fig.update_yaxes(autorange=False, range=[0, height_meter], scaleanchor="x", scaleratio=1)
fig.update_layout(
title=go.layout.Title(
text=title or "No title.",
xref="paper",
x=0,
),
autosize=True,
width=900,
height=200 + 900 * height_meter / width_meter,
template="plotly_white",
)
if show:
fig.show()
return fig