mirror of
https://github.com/AtsushiSakai/PythonRobotics.git
synced 2026-01-30 20:57:54 -05:00
first release universal sampling method
This commit is contained in:
89
PathPlanning/StateLatticePlanner/matplotrecorder/.gitignore
vendored
Normal file
89
PathPlanning/StateLatticePlanner/matplotrecorder/.gitignore
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
.hypothesis/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# IPython Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# dotenv
|
||||
.env
|
||||
|
||||
# virtualenv
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
21
PathPlanning/StateLatticePlanner/matplotrecorder/LICENSE
Normal file
21
PathPlanning/StateLatticePlanner/matplotrecorder/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Atsushi Sakai
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
59
PathPlanning/StateLatticePlanner/matplotrecorder/README.md
Normal file
59
PathPlanning/StateLatticePlanner/matplotrecorder/README.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# matplotrecorder
|
||||
A simple Python module for recording matplotlib animation
|
||||
|
||||
It can generate a matplotlib animation movie (mp4, gif, etc.)
|
||||
|
||||
This tool use "convert" command of ImageMagick.
|
||||
|
||||
# Sample gif
|
||||
|
||||

|
||||
|
||||
# Requrements
|
||||
|
||||
- [ImageMagic](https://www.imagemagick.org/script/index.php)
|
||||
|
||||
|
||||
# How to use
|
||||
|
||||
Call save_frame() at each animation iteration,
|
||||
|
||||
And then, call savemovie() for movie generation.
|
||||
|
||||
A sample code:
|
||||
|
||||
|
||||
import matplotrecorder
|
||||
|
||||
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)
|
||||
|
||||
matplotrecorder.save_frame() # save each frame
|
||||
|
||||
# generate movie
|
||||
matplotrecorder.save_movie("animation.mp4", 0.1)
|
||||
# matplotrecorder.save_movie("animation.gif", 0.1) #gif is ok.
|
||||
|
||||
|
||||
|
||||
# License
|
||||
|
||||
MIT
|
||||
|
||||
# Author
|
||||
|
||||
Atsushi Sakai ([@Atsushi_twi](https://twitter.com/Atsushi_twi))
|
||||
|
||||
BIN
PathPlanning/StateLatticePlanner/matplotrecorder/animation.gif
Normal file
BIN
PathPlanning/StateLatticePlanner/matplotrecorder/animation.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 311 KiB |
BIN
PathPlanning/StateLatticePlanner/matplotrecorder/animation.mp4
Normal file
BIN
PathPlanning/StateLatticePlanner/matplotrecorder/animation.mp4
Normal file
Binary file not shown.
@@ -0,0 +1,74 @@
|
||||
"""
|
||||
A simple Python module for recording matplotlib animation
|
||||
|
||||
This tool use convert command of ImageMagick
|
||||
|
||||
author: Atsushi Sakai
|
||||
|
||||
How to use:
|
||||
|
||||
- import
|
||||
|
||||
from matplotrecorder import matplotrecorder
|
||||
|
||||
- save file
|
||||
|
||||
matplotrecorder.save_frame()
|
||||
|
||||
- generate movie
|
||||
|
||||
matplotrecorder.save_movie("animation.gif", 0.1)
|
||||
|
||||
"""
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import subprocess
|
||||
|
||||
iframe = 0
|
||||
donothing = False # switch to stop all recordering
|
||||
|
||||
|
||||
def save_frame():
|
||||
"""
|
||||
Save a frame for movie
|
||||
"""
|
||||
|
||||
if not donothing:
|
||||
global iframe
|
||||
plt.savefig("recoder" + '{0:04d}'.format(iframe) + '.png')
|
||||
iframe += 1
|
||||
|
||||
|
||||
def save_movie(fname, d_pause):
|
||||
"""
|
||||
Save movie as gif
|
||||
"""
|
||||
if not donothing:
|
||||
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