forked from jesseinouye/RP_maze_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_path.py
More file actions
73 lines (51 loc) · 2.89 KB
/
Copy pathplot_path.py
File metadata and controls
73 lines (51 loc) · 2.89 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
import numpy as np
from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
def visualize_paths(pred_path, html_title="", file_out="plot.html"):
output_file(file_out, title=html_title)
pred_path = np.array(pred_path) # Convert to NumPy array if not already done
# Extract x and y coordinates
pred_x, pred_y = pred_path.T
# Create ColumnDataSource with only path data
source = ColumnDataSource(data=dict(px=pred_x, py=pred_y))
tools = "pan,wheel_zoom,box_zoom,box_select,lasso_select,reset"
# Create the figure for paths
fig = figure(title="Paths", tools=tools, match_aspect=True, width_policy="max",
toolbar_location="above", x_axis_label="x", y_axis_label="y")
# Plot the paths using circles and lines
fig.circle("px", "py", source=source, color="green", legend_label="Paths")
fig.line("px", "py", source=source, color="green", legend_label="Paths")
# Set the legend interaction policy
fig.legend.click_policy = "hide"
# Show the plot
show(fig)
def visualize_paths_with_target(pred_path, possible_targets, html_title="", file_out="plot.html"):
output_file(file_out, title=html_title)
pred_path = np.array(pred_path) # Convert to NumPy array if not already done
# Extract x and y coordinates
pred_x, pred_y = pred_path.T
target_x = [tar[0] for tar in possible_targets]
target_y = [tar[1] for tar in possible_targets]
# Create ColumnDataSource with only path data
source = ColumnDataSource(data=dict(px=pred_x, py=pred_y))
tools = "pan,wheel_zoom,box_zoom,box_select,lasso_select,reset"
# Create the figure for paths
fig = figure(title="Paths", tools=tools, match_aspect=True, width_policy="max",
toolbar_location="above", x_axis_label="x", y_axis_label="y")
# Plot the paths using circles and lines
fig.circle("px", "py", source=source, color="green", legend_label="Paths")
fig.line("px", "py", source=source, color="green", legend_label="Paths")
# print("Adding target location: {}, {}".format(target_loc[0], target_loc[1]))
fig.circle(x=[possible_targets[0][0]], y=[possible_targets[0][1]], color="red", legend_label="match 1", size=10)
fig.circle(x=[possible_targets[1][0]], y=[possible_targets[1][1]], color="orange", legend_label="match 2", size=10)
fig.circle(x=[possible_targets[2][0]], y=[possible_targets[2][1]], color="pink", legend_label="match 3", size=10)
fig.circle(x=[possible_targets[3][0]], y=[possible_targets[3][1]], color="purple", legend_label="match 4", size=10)
# fig.circle(x=target_x, y=target_y, color="red", legend_label="Target", size=10)
# Set the legend interaction policy
fig.legend.click_policy = "hide"
# Show the plot
show(fig)
# Example usage:
# Assuming pred_path is your data containing the paths
# visualize_paths(pred_path)