irsim.env.env_plot#
This file is the implementation of the environment plot to visualize the environment objects.
Author: Ruihua Han
Classes#
EnvPlot class for visualizing the environment. |
Functions#
|
Convert a linewidth in data units to linewidth in points. |
Module Contents#
- class irsim.env.env_plot.EnvPlot(world: Any, objects: list[Any] | None = None, saved_figure: dict[str, Any] | None = None, figure_pixels: collections.abc.Sequence[int] | None = None, show_title: bool = True, **kwargs: Any)[source]#
EnvPlot class for visualizing the environment.
- Parameters:
world – The world object containing environment information including grid_map, x_range, y_range.
objects (list, optional) – List of objects in the environment. Default is [].
saved_figure (dict, optional) – Keyword arguments for saving the figure. See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html for details. Default is dict().
figure_pixels (list, optional) – Width and height of the figure in pixels. Default is [1180, 1080].
show_title (bool, optional) – Whether to show the title. Default is True.
kwargs – Additional options such as color_map, no_axis, and tight.
Initialize the EnvPlot instance.
Sets up the matplotlib figure, configures plotting parameters, and initializes the plot with world data and objects.
- world#
- x_range#
- y_range#
- show_title = True#
- title = None#
- saved_figure_kwargs: dict[str, Any]#
- color_map: dict[str, str]#
- saved_ani_kwargs: dict[str, Any]#
- dyna_line_list: list[Any] = []#
- dyna_point_list: list[Any] = []#
- dyna_quiver_list: list[Any] = []#
- init_plot(grid_map: Any | None, objects: list[Any], no_axis: bool = False, tight: bool = True, **kwargs: Any) None[source]#
Initialize the plot with the given grid map and objects.
- Parameters:
grid_map (optional) – The grid map of the environment.
objects (list) – List of objects to plot.
no_axis (bool, optional) – Whether to show the axis. Default is False.
tight (bool, optional) – Whether to show the axis tightly. Default is True.
- step(mode: str = 'dynamic', objects: list[Any] | None = None, **kwargs: Any) None[source]#
Advance the plot by one step for the given objects.
- Parameters:
mode (str) – Which objects to update: “dynamic”, “static”, or “all”.
objects (list | None) – The objects to update/draw. Defaults to empty list.
**kwargs – Extra drawing options passed through to objects’ plot methods.
- init_objects_plot(objects: list[Any], **kwargs: Any) None[source]#
Initialize plot state for provided objects, then render once.
- Parameters:
objects (list) – Objects to be initialized on the axes.
**kwargs – Extra drawing options passed to initialization/plot.
- step_objects_plot(mode: str = 'dynamic', objects: list[Any] | None = None, **kwargs: Any) None[source]#
Update the plot for the objects.
- draw_components(mode: str = 'all', objects: list[Any] | None = None, **kwargs: Any) None[source]#
Draw the components in the environment.
- Parameters:
mode (str) – ‘static’, ‘dynamic’, or ‘all’ to specify which objects to draw.
objects (list) – List of objects to draw.
kwargs – Additional plotting options.
- clear_components(mode: str = 'all', objects: list[Any] | None = None) None[source]#
Clear the components in the environment.
- Parameters:
mode (str) – ‘static’, ‘dynamic’, or ‘all’ to specify which objects to clear.
objects (list) – List of objects to clear.
- draw_grid_map(grid_map: Any | None = None, **kwargs: Any) None[source]#
Draw the grid map on the plot.
- Parameters:
grid_map (optional) – The grid map to draw.
- draw_trajectory(traj: list[Any] | numpy.ndarray, traj_type: str = 'g-', label: str = 'trajectory', show_direction: bool = False, refresh: bool = False, **kwargs: Any) None[source]#
Draw a trajectory on the plot.
- Parameters:
traj (list or np.ndarray) – List of points or array of points [x, y, theta].
traj_type (str) – Type of trajectory line (e.g., ‘g-‘). See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.plot.html for details.
label (str) – Label for the trajectory.
show_direction (bool) – Whether to show the direction of the trajectory.
refresh (bool) – Whether to refresh the plot.
kwargs – Additional plotting options for ax.plot()
- draw_points(points: list[Any] | numpy.ndarray | None, s: int = 10, c: str = 'm', refresh: bool = True, **kwargs: Any) None[source]#
Draw points on the plot.
- Parameters:
points (list) – List of points, each point as [x, y] or (2, 1) array or (np.array): points array: (2, N), NL number of points
s (int) – Size of the points.
c (str) – Color of the points.
refresh (bool) – Whether to refresh the plot.
kwargs – Additional plotting options.
- draw_quiver(point: numpy.ndarray | None, refresh: bool = False, color: str = 'black', **kwargs: Any) None[source]#
Draw a quiver plot on the plot.
- Parameters:
points (4*1 np.ndarray) – List of points, each point as [x, y, u, v]. u, v are the components of the vector.
kwargs – Additional plotting options.
- draw_quivers(points: collections.abc.Iterable[numpy.ndarray], refresh: bool = False, color: str = 'black', **kwargs: Any) None[source]#
Draw a series of quiver plot on the plot.
- Parameters:
points (list or np.ndarray) – List of points, each point as [x, y, u, v]. u, v are the components of the vector.
- draw_box(vertices: numpy.ndarray, refresh: bool = False, color: str = 'b-') None[source]#
Draw a box by the vertices.
- Parameters:
vertices (np.ndarray) – 2xN array of vertices.
refresh (bool) – Whether to refresh the plot.
color (str) – Color and line type of the box.
- save_figure(file_name: str = '', file_format: str = 'png', include_index: bool = False, save_gif: bool = False, **kwargs: Any) None[source]#
Save the current figure.
- Parameters:
file_name (str) – Name of the figure. Default is ‘’.
file_format (str) – Format of the figure. Default is ‘png’.
kwargs – Additional arguments for saving the figure. See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html for details.
- save_animate(ani_name: str = 'animation', suffix: str = '.gif', last_frame_duration: int = 1, rm_fig_path: bool = True, **kwargs: Any) None[source]#
Save the animation.
- Parameters:
ani_name (str) – Name of the animation. Default is ‘animation’.
last_frame_duration (int) – Duration of the last frame for the gif. Default is 1 second.
suffix (str) – Suffix of the animation file. Default is ‘.gif’.
rm_fig_path (bool) – Whether to remove the figure path after saving. Default is True.
kwargs – Additional arguments for saving the animation. See imageio.imwrite for details.
- property logger#
- irsim.env.env_plot.linewidth_from_data_units(linewidth: float, axis: Any, reference: str = 'y') float[source]#
Convert a linewidth in data units to linewidth in points.
- Parameters:
linewidth (float) – Linewidth in data units of the respective reference-axis
axis (matplotlib axis) – The axis which is used to extract the relevant transformation data (data limits and size must not change afterwards)
reference (string) – The axis that is taken as a reference for the data width. Possible values: ‘x’ and ‘y’. Defaults to ‘y’.
- Returns:
linewidth – Linewidth in points
- Return type:
float