Skip to content

Commit 76bb410

Browse files
authored
Add logic to plot the found path and show the start and the end
1 parent 9b4190f commit 76bb410

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/EXAMPLES.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,22 @@ Sometimes it is hard to see the finer points of a maze in plain text. You may wa
121121

122122
import matplotlib.pyplot as plt
123123

124-
def showPNG(grid):
124+
def showPNG(grid, start=None, end=None, shortest_path=None):
125125
"""Generate a simple image of the maze."""
126126
plt.figure(figsize=(10, 5))
127127
plt.imshow(grid, cmap=plt.cm.binary, interpolation='nearest')
128128
plt.xticks([]), plt.yticks([])
129+
# plot start and end
130+
if start is not None:
131+
plt.plot(start[1], start[0], 'o', markersize=10, color='green')
132+
if end is not None:
133+
plt.plot(end[1], end[0], 'o', markersize=10, color='red')
134+
# plot the shortest path
135+
if shortest_path is not None:
136+
plt.plot([p[1] for p in shortest_path], [p[0] for p in shortest_path], linewidth=3, color='cyan')
129137
plt.show()
130138

139+
131140
![Prims Example](images/prims_5x5_plain.png?raw=true)
132141

133142

0 commit comments

Comments
 (0)