irsim.env.env_plot ================== .. py:module:: irsim.env.env_plot .. autoapi-nested-parse:: This file is the implementation of the environment plot to visualize the environment objects. Author: Ruihua Han Classes ------- .. autoapisummary:: irsim.env.env_plot.EnvPlot Functions --------- .. autoapisummary:: irsim.env.env_plot.linewidth_from_data_units irsim.env.env_plot.draw_patch irsim.env.env_plot.set_patch_property Module Contents --------------- .. py:class:: EnvPlot(world: Any, objects: list[Any] | None = None, **kwargs: Any) EnvPlot class for visualizing the environment. :param world: The world object with ranges and a ``plot_parse`` dictionary that configures plotting (e.g., saved_figure, figure_pixels, show_title, no_axis, tight). :param objects: Initial objects to draw. Default is ``[]``. :type objects: list, optional :param kwargs: Plot overrides that update ``world.plot_parse`` at runtime (e.g., ``saved_figure``, ``figure_pixels``, ``show_title``, ``no_axis``, ``tight``). Initialize the EnvPlot instance. Sets up the matplotlib figure, configures plotting parameters, and initializes the plot with world data and objects. Any provided ``kwargs`` override values in ``world.plot_parse``. .. py:attribute:: saved_figure_kwargs :type: dict[str, Any] .. py:attribute:: viewpoint .. py:attribute:: dyna_line_list :type: list[Any] :value: [] .. py:attribute:: dyna_point_list :type: list[Any] :value: [] .. py:attribute:: dyna_quiver_list :type: list[Any] :value: [] .. py:method:: step(mode: str = 'dynamic', objects: list[Any] | None = None, **kwargs: Any) -> None Advance the plot by one step for the given objects. :param mode: Which objects to update: "dynamic", "static", or "all". :type mode: str :param objects: The objects to update/draw. Defaults to empty list. :type objects: list | None :param \*\*kwargs: Extra drawing options passed through to objects' plot methods. .. py:method:: init_objects_plot(objects: list[Any], **kwargs: Any) -> None Initialize plot state for provided objects, then render once. :param objects: Objects to be initialized on the axes. :type objects: list :param \*\*kwargs: Extra drawing options passed to initialization/plot. .. py:method:: step_objects_plot(mode: str = 'dynamic', objects: list[Any] | None = None, **kwargs: Any) -> None Update the plot for the objects by transform based on the object's original geometry. .. py:method:: draw_components(mode: str = 'all', objects: list[Any] | None = None, **kwargs: Any) -> None Draw the components in the environment with global axis. :param mode: 'static', 'dynamic', or 'all' to specify which objects to draw. :type mode: str :param objects: List of objects to draw. :type objects: list :param kwargs: Additional plotting options. .. py:method:: clear_components(mode: str = 'all', objects: list[Any] | None = None) -> None Clear the components in the environment. :param mode: 'static', 'dynamic', or 'all' to specify which objects to clear. :type mode: str :param objects: List of objects to clear. :type objects: list .. py:method:: draw_grid_map(grid_map: Any | None = None, **kwargs: Any) -> None Draw the grid map on the plot. :param grid_map: The grid map to draw. :type grid_map: optional .. py:method:: draw_trajectory(traj: list[Any] | numpy.ndarray, traj_type: str = 'g-', label: str = 'trajectory', show_direction: bool = False, refresh: bool = False, **kwargs: Any) -> None Draw a trajectory on the plot. :param traj: List of points or array of points [x, y, theta]. :type traj: list or np.ndarray :param traj_type: Type of trajectory line (e.g., 'g-'). See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.plot.html for details. :type traj_type: str :param label: Label for the trajectory. :type label: str :param show_direction: Whether to show the direction of the trajectory. :type show_direction: bool :param refresh: Whether to refresh the plot. :type refresh: bool :param kwargs: Additional plotting options for ax.plot() .. py:method:: draw_points(points: list[Any] | numpy.ndarray | None, s: int = 10, c: str = 'm', refresh: bool = True, **kwargs: Any) -> None Draw points on the plot. :param points: List of points, each point as [x, y] or (2, 1) array or (np.array): points array: (2, N), NL number of points :type points: list :param s: Size of the points. :type s: int :param c: Color of the points. :type c: str :param refresh: Whether to refresh the plot. :type refresh: bool :param kwargs: Additional plotting options. .. py:method:: draw_quiver(point: numpy.ndarray | None, refresh: bool = False, color: str = 'black', **kwargs: Any) -> None Draw a quiver plot on the plot. :param points: List of points, each point as [x, y, u, v]. u, v are the components of the vector. :type points: 4*1 np.ndarray :param kwargs: Additional plotting options. .. py:method:: draw_quivers(points: collections.abc.Iterable[numpy.ndarray], refresh: bool = False, color: str = 'black', **kwargs: Any) -> None Draw a series of quiver plot on the plot. :param points: List of points, each point as [x, y, u, v]. u, v are the components of the vector. :type points: list or np.ndarray .. py:method:: draw_box(vertices: numpy.ndarray, refresh: bool = False, color: str = 'b-') -> None Draw a box by the vertices. :param vertices: 2xN array of vertices. :type vertices: np.ndarray :param refresh: Whether to refresh the plot. :type refresh: bool :param color: Color and line type of the box. :type color: str .. py:method:: update_title() -> None Update the figure title with current time/status or a custom title. .. py:method:: save_figure(file_name: str = '', file_format: str = 'png', include_index: bool = False, save_gif: bool = False, **kwargs: Any) -> None Save the current figure. :param file_name: Name of the figure. Default is ''. :type file_name: str :param file_format: Format of the figure. Default is 'png'. :type file_format: str :param kwargs: Additional arguments for saving the figure. See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html for details. .. py:method:: save_animate(ani_name: str = 'animation', suffix: str = '.gif', last_frame_duration: int = 1, rm_fig_path: bool = True, **kwargs: Any) -> None Save the animation by streaming frames to avoid loading all images into memory. :param ani_name: Name of the animation. Default is 'animation'. :type ani_name: str :param last_frame_duration: Duration of the last frame for the gif. Default is 1 second. :type last_frame_duration: int :param suffix: Suffix of the animation file. Default is '.gif'. :type suffix: str :param rm_fig_path: Whether to remove the figure path after saving. Default is True. :type rm_fig_path: bool :param kwargs: Additional arguments for saving the animation. For GIF: See pillow plugin documentation. For video: See ffmpeg/pyav plugin documentation. .. py:method:: set_ax_viewpoint(objects: list[Any] | None = None) -> None Set the viewpoint of the plot windows by the viewpoint parameter. :param objects: List of objects to search for the viewpoint. :type objects: list .. py:method:: show() -> None Display the plot. .. py:method:: close() -> None Close the plot. .. py:property:: logger .. py:property:: x_range .. py:property:: y_range .. py:function:: linewidth_from_data_units(linewidth: float, axis: Any, reference: str = 'y') -> float Convert a linewidth in data units to linewidth in points. :param linewidth: Linewidth in data units of the respective reference-axis :type linewidth: float :param axis: The axis which is used to extract the relevant transformation data (data limits and size must not change afterwards) :type axis: matplotlib axis :param reference: The axis that is taken as a reference for the data width. Possible values: 'x' and 'y'. Defaults to 'y'. :type reference: string :returns: **linewidth** -- Linewidth in points :rtype: float .. py:function:: draw_patch(ax: Any, shape: str, state: numpy.ndarray | None = None, radius: float | None = None, vertices: numpy.ndarray | None = None, color: str | None = None, zorder: int | None = None, linestyle: str | None = None, **kwargs: Any) -> Any Draw a geometric element (patch or line) on the given axes. Supported shapes and expected inputs (refer to irsim.world.object_base plotting patterns): - circle: use ``state`` (x,y,theta) and ``radius``; created at origin and transformed - rectangle: prefer ``vertices`` (2xN) else use ``width``/``height`` with ``state`` transform - polygon: use ``vertices`` (2xN) - ellipse: use ``width``/``height`` with ``state`` transform - wedge: use ``radius`` and either ``theta1``/``theta2`` (deg) or ``fov`` (rad); transformed by ``state`` - arrow: use ``state`` for position/orientation or provide ``theta``; supports ``arrow_length`` and ``arrow_width`` - line|linestring: use ``vertices`` (2xN) to draw a line element Styling: - color/edgecolor/facecolor, alpha, zorder, linestyle are respected when applicable. Returns the created matplotlib artist (patch, line, or list from ax.plot). .. py:function:: set_patch_property(element: Any, ax: Any, state: numpy.ndarray | None = None, **kwargs: Any) -> None Apply transform and style properties to a patch/artist, matching ObjectBase semantics. - If ``state`` provided with at least 3 rows, apply rotation by theta and translation by (x, y). - Apply color/facecolor/edgecolor, alpha, zorder, linestyle when supported.