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, objects=[], saved_figure=dict(), figure_pixels: list = [1000, 800], show_title: bool = True, **kwargs)[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#
- color_map#
- saved_ani_kwargs#
- dyna_line_list = []#
- dyna_point_list = []#
- dyna_quiver_list = []#
- init_plot(grid_map, objects, no_axis=False, tight=True, **kwargs)[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.
- draw_components(mode='all', objects=[], **kwargs)[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='all', objects=[])[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=None, **kwargs)[source]#
Draw the grid map on the plot.
- Parameters:
grid_map (optional) – The grid map to draw.
- draw_trajectory(traj, traj_type='g-', label='trajectory', show_direction=False, refresh=False, **kwargs)[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, s=10, c='m', refresh=True, **kwargs)[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, refresh=False, color='black', **kwargs)[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, refresh=False, color='black', **kwargs)[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, refresh=False, color='b-')[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='', file_format='png', include_index=False, save_gif=False, **kwargs)[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='animation', suffix='.gif', last_frame_duration=1, rm_fig_path=True, **kwargs)[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, axis, reference='y')[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