Files
PythonRobotics/utils/plot.py
Atsushi Sakai 31178c8e37 Enhance dubins path docs (#679)
* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs

* Enhance dubins path docs
2022-05-17 21:57:07 +09:00

50 lines
1.6 KiB
Python

"""
Matplotlib based plotting utilities
"""
import math
import matplotlib.pyplot as plt
def plot_arrow(x, y, yaw, arrow_length=1.0,
origin_point_plot_style="xr",
head_width=0.1, fc="r", ec="k", **kwargs):
"""
Plot an arrow or arrows based on 2D state (x, y, yaw)
All optional settings of matplotlib.pyplot.arrow can be used.
- matplotlib.pyplot.arrow:
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.arrow.html
Parameters
----------
x : a float or array_like
a value or a list of arrow origin x position.
y : a float or array_like
a value or a list of arrow origin y position.
yaw : a float or array_like
a value or a list of arrow yaw angle (orientation).
arrow_length : a float (optional)
arrow length. default is 1.0
origin_point_plot_style : str (optional)
origin point plot style. If None, not plotting.
head_width : a float (optional)
arrow head width. default is 0.1
fc : string (optional)
face color
ec : string (optional)
edge color
"""
if not isinstance(x, float):
for (i_x, i_y, i_yaw) in zip(x, y, yaw):
plot_arrow(i_x, i_y, i_yaw, head_width=head_width,
fc=fc, ec=ec, **kwargs)
else:
plt.arrow(x, y,
arrow_length * math.cos(yaw),
arrow_length * math.sin(yaw),
head_width=head_width,
fc=fc, ec=ec,
**kwargs)
if origin_point_plot_style is not None:
plt.plot(x, y, origin_point_plot_style)