mirror of
https://github.com/AtsushiSakai/PythonRobotics.git
synced 2026-01-14 01:28:23 -05:00
add matplotrecorder and result
This commit is contained in:
BIN
scripts/PathPlanning/RRTCar/figure_1.png
Normal file
BIN
scripts/PathPlanning/RRTCar/figure_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 271 KiB |
56
scripts/PathPlanning/RRTCar/matplotrecorder.py
Normal file
56
scripts/PathPlanning/RRTCar/matplotrecorder.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""
|
||||
A simple Python module for recording matplotlib animation
|
||||
|
||||
This tool use convert command of ImageMagick
|
||||
|
||||
author: Atsushi Sakai
|
||||
"""
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import subprocess
|
||||
|
||||
iframe = 0
|
||||
|
||||
|
||||
def save_frame():
|
||||
"""
|
||||
Save a frame for movie
|
||||
"""
|
||||
global iframe
|
||||
|
||||
plt.savefig("recoder" + '{0:04d}'.format(iframe) + '.png')
|
||||
iframe += 1
|
||||
|
||||
|
||||
def save_movie(fname, d_pause):
|
||||
"""
|
||||
Save movie as gif
|
||||
"""
|
||||
cmd = "convert -delay " + str(int(d_pause * 100)) + \
|
||||
" recoder*.png " + fname
|
||||
subprocess.call(cmd, shell=True)
|
||||
cmd = "rm recoder*.png"
|
||||
subprocess.call(cmd, shell=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("A sample recording start")
|
||||
import math
|
||||
|
||||
time = range(50)
|
||||
|
||||
x1 = [math.cos(t / 10.0) for t in time]
|
||||
y1 = [math.sin(t / 10.0) for t in time]
|
||||
x2 = [math.cos(t / 10.0) + 2 for t in time]
|
||||
y2 = [math.sin(t / 10.0) + 2 for t in time]
|
||||
|
||||
for ix1, iy1, ix2, iy2 in zip(x1, y1, x2, y2):
|
||||
plt.plot(ix1, iy1, "xr")
|
||||
plt.plot(ix2, iy2, "xb")
|
||||
plt.axis("equal")
|
||||
plt.pause(0.1)
|
||||
|
||||
save_frame() # save each frame
|
||||
|
||||
save_movie("animation.gif", 0.1)
|
||||
# save_movie("animation.mp4", 0.1)
|
||||
Reference in New Issue
Block a user