Example #1
0
def plot_coordinate_systems(
    cs_data: Tuple[str, Dict],
    axes: Axes = None,
    title: str = None,
    limits: types_limits = None,
    time_index: int = None,
    legend_pos: str = "lower left",
) -> Axes:
    """Plot multiple coordinate systems.

    Parameters
    ----------
    cs_data :
        A tuple containing the coordinate system that should be plotted and a dictionary
        with the key word arguments that should be passed to its plot function.
    axes :
        The target axes object that should be drawn to. If `None` is provided, a new
        one will be created.
    title :
        The title of the plot
    limits :
        Each tuple marks lower and upper boundary of the x, y and z axis. If only a
        single tuple is passed, the boundaries are used for all axis. If `None`
        is provided, the axis are adjusted to be of equal length.
    time_index :
        Index of a specific time step that should be plotted if the corresponding
        coordinate system is time dependent
    legend_pos :
        A string that specifies the position of the legend. See the matplotlib
        documentation for further details

    Returns
    -------
    matplotlib.axes.Axes :
        The axes object that was used as canvas for the plot

    """
    if axes is None:
        _, axes = new_3d_figure_and_axes()

    for lcs, kwargs in cs_data:
        if "time_index" not in kwargs:
            kwargs["time_index"] = time_index
        lcs.plot(axes, **kwargs)

    _set_limits_matplotlib(axes, limits)

    if title is not None:
        axes.set_title(title)
    axes.legend(loc=legend_pos)

    return axes
Example #2
0
    def show_mask(self, ax: axes.Axes, title="", fontfamily="times new roman", fontsize=15, scatter=20):

        phi = np.linspace(0, 2 * np.pi, 360 * 4)
        circle = ax.fill(self._aperture * np.cos(phi), self._aperture * np.sin(phi), color="lightblue", zorder=0)
        elements = ax.scatter(x=self._locations[0], y=self._locations[1], s=scatter, c="gray", zorder=2)

        if title == "":
            title = "Total number: " + str(self.get_total_number())

        # loop line
        for radius in self._radius:
            ax.plot(radius * np.cos(phi), radius * np.sin(phi), color="orange", zorder=1)

        ax.set_aspect("equal", 'box')
        ax.set_axis_off()
        ax.grid(True)
        ax.set_title(title, fontsize=fontsize, fontfamily=fontfamily)
        return ax
Example #3
0
def show_rdm_panel(
    rdm: rsatoolbox.rdm.RDMs,
    ax: Axes = None,
    cmap: Union[str, matplotlib.colors.Colormap] = None,
    nanmask: npt.ArrayLike = None,
    rdm_descriptor: str = None,
    gridlines: npt.ArrayLike = None,
    vmin: float = None,
    vmax: float = None,
) -> matplotlib.image.AxesImage:
    """show_rdm_panel. Add RDM heatmap to the axis ax.

    Args:
        rdm (rsatoolbox.rdm.RDMs): RDMs object to be plotted (n_rdm must be 1).
        ax (matplotlib.axes._axes.Axes): Matplotlib axis handle. plt.gca() by default.
        cmap (Union[str, matplotlib.colors.Colormap]): colormap to be used (by
            plt.imshow internally). By default we use rdm_colormap.
        nanmask (npt.ArrayLike): boolean mask defining RDM elements to suppress
            (by default, the diagonals).
        rdm_descriptor (str): Key for rdm_descriptor to use as panel title, or
            str for direct labeling.
        gridlines (npt.ArrayLike): Set to add gridlines at these positions.
        vmin (float): Minimum intensity for colorbar mapping. matplotlib imshow
            argument.
        vmax (float): Maximum intensity for colorbar mapping. matplotlib imshow
            argument.

    Returns:
        matplotlib.image.AxesImage: Matplotlib handle.
    """
    if rdm.n_rdm > 1:
        raise ValueError(
            "expected single rdm - use show_rdm for multi-panel figures")
    if ax is None:
        ax = plt.gca()
    if cmap is None:
        cmap = rdm_colormap()
    if nanmask is None:
        nanmask = np.eye(rdm.n_cond, dtype=bool)
    if not np.any(gridlines):
        gridlines = []
    rdmat = rdm.get_matrices()[0, :, :]
    if np.any(nanmask):
        rdmat[nanmask] = np.nan
    image = ax.imshow(rdmat, cmap=cmap, vmin=vmin, vmax=vmax)
    ax.set_xlim(-0.5, rdm.n_cond - 0.5)
    ax.set_ylim(rdm.n_cond - 0.5, -0.5)
    ax.xaxis.set_ticks(gridlines)
    ax.yaxis.set_ticks(gridlines)
    ax.xaxis.set_ticklabels([])
    ax.yaxis.set_ticklabels([])
    ax.xaxis.set_ticks(np.arange(rdm.n_cond), minor=True)
    ax.yaxis.set_ticks(np.arange(rdm.n_cond), minor=True)
    # hide minor ticks by default
    ax.xaxis.set_tick_params(length=0, which="minor")
    ax.yaxis.set_tick_params(length=0, which="minor")
    if rdm_descriptor in rdm.rdm_descriptors:
        ax.set_title(rdm.rdm_descriptors[rdm_descriptor][0])
    else:
        ax.set_title(rdm_descriptor)
    return image
Example #4
0
def plot_coordinate_system_manager_matplotlib(
    csm: CoordinateSystemManager,
    axes: Axes = None,
    reference_system: str = None,
    coordinate_systems: List[str] = None,
    data_sets: List[str] = None,
    colors: Dict[str, int] = None,
    time: types_timeindex = None,
    time_ref: pd.Timestamp = None,
    title: str = None,
    limits: types_limits = None,
    scale_vectors: Union[float, List, np.ndarray] = None,
    set_axes_equal: bool = False,
    show_origins: bool = True,
    show_trace: bool = True,
    show_vectors: bool = True,
    show_wireframe: bool = True,
) -> Axes:
    """Plot the coordinate systems of a `weldx.transformations.CoordinateSystemManager`.

    Parameters
    ----------
    csm :
        The coordinate system manager instance that should be plotted.
    axes :
        The target axes object that should be drawn to. If `None` is provided, a new
        one will be created.
    reference_system :
        The name of the reference system for the plotted coordinate systems
    coordinate_systems :
        Names of the coordinate systems that should be drawn. If `None` is provided,
        all systems are plotted.
    data_sets :
        Names of the data sets that should be drawn. If `None` is provided, all data
        is plotted.
    colors :
        A mapping between a coordinate system name or a data set name and a color.
        The colors must be provided as 24 bit integer values that are divided into
        three 8 bit sections for the rgb values. For example `0xFF0000` for pure
        red.
        Each coordinate system or data set that does not have a mapping in this
        dictionary will get a default color assigned to it.
    time :
        The time steps that should be plotted
    time_ref :
        A reference timestamp that can be provided if the ``time`` parameter is a
        `pandas.TimedeltaIndex`
    title :
        The title of the plot
    limits :
        Each tuple marks lower and upper boundary of the x, y and z axis. If only a
        single tuple is passed, the boundaries are used for all axis. If `None`
        is provided, the axis are adjusted to be of equal length.
    scale_vectors :
        A scaling factor or array to adjust the length of the coordinate system vectors
    set_axes_equal :
        (matplotlib only) If `True`, all axes are adjusted to cover an equally large
         range of value. That doesn't mean, that the limits are identical
    show_origins :
        If `True`, the origins of the coordinate system are visualized in the color
        assigned to the coordinate system.
    show_trace :
        If `True`, the trace of time dependent coordinate systems is plotted.
    show_vectors :
        If `True`, the coordinate cross of time dependent coordinate systems is plotted.
    show_wireframe :
        If `True`, the mesh is visualized as wireframe. Otherwise, it is not shown.

    Returns
    -------
    matplotlib.axes.Axes :
        The axes object that was used as canvas for the plot.

    """
    if time is not None:
        return plot_coordinate_system_manager_matplotlib(
            csm.interp_time(time=time, time_ref=time_ref),
            axes=axes,
            reference_system=reference_system,
            coordinate_systems=coordinate_systems,
            title=title,
            show_origins=show_origins,
            show_trace=show_trace,
            show_vectors=show_vectors,
        )
    if axes is None:
        _, axes = new_3d_figure_and_axes()
        axes.set_xlabel("x")
        axes.set_ylabel("y")
        axes.set_zlabel("z")

    if reference_system is None:
        reference_system = csm.root_system_name
    if coordinate_systems is None:
        coordinate_systems = csm.coordinate_system_names
    if data_sets is None:
        data_sets = csm.data_names
    if title is not None:
        axes.set_title(title)

    # plot coordinate systems
    color_gen = color_generator_function()
    for lcs_name in coordinate_systems:
        color = color_int_to_rgb_normalized(
            get_color(lcs_name, colors, color_gen))
        lcs = csm.get_cs(lcs_name, reference_system)
        lcs.plot(
            axes=axes,
            color=color,
            label=lcs_name,
            scale_vectors=scale_vectors,
            show_origin=show_origins,
            show_trace=show_trace,
            show_vectors=show_vectors,
        )
    # plot data
    for data_name in data_sets:
        color = color_int_to_rgb_normalized(
            get_color(data_name, colors, color_gen))
        data = csm.get_data(data_name, reference_system)
        plot_spatial_data_matplotlib(
            data=data,
            axes=axes,
            color=color,
            label=data_name,
            show_wireframe=show_wireframe,
        )

    _set_limits_matplotlib(axes, limits, set_axes_equal)
    axes.legend()

    return axes