Exemplo n.º 1
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
Exemplo n.º 2
0
def IFT_LoopMaskArray(aperture, loop_number: np.array, loop_radius: np.array, ax: axes.Axes, centred=False):
    """
    Draw circular array on the circular aperture face
    :param aperture: the radius of the array
    :param loop_number: number of each loop
    :param loop_radius: radius of each loop
    :param ax: handle of subplot
    :param centred: the centre whether has the element for True or False
    :return:
    """
    detal_phi = 2 * np.pi / loop_number
    total_number = np.einsum("i->", loop_number)

    if centred:
        loc = np.zeros([2, total_number + 1], dtype=np.float64)
        loop_index = 1
    else:
        loc = np.zeros([2, total_number], dtype=np.float64)
        loop_index = 0

    for zmc, radius in enumerate(loop_radius):
        current_number = loop_number[zmc]
        phi = np.arange(0, current_number) * detal_phi[zmc]
        loc_x = radius * np.cos(phi)
        loc_y = radius * np.sin(phi)
        loc[0, loop_index:loop_index + current_number] = loc_x
        loc[1, loop_index:loop_index + current_number] = loc_y
        loop_index = loop_index + current_number

    phi = np.linspace(0, 2 * np.pi, 360 * 4)

    # draw
    circle = ax.fill(aperture * np.cos(phi), aperture * np.sin(phi), color='lightblue', zorder=0)
    elements = ax.scatter(x=loc[0], y=loc[1], s=10, c='gray', zorder=1)

    ax.set_aspect('equal', 'box')
    ax.set_axis_off()
    ax.grid(True)

    return ax
Exemplo n.º 3
0
def plot_spatial_data_matplotlib(
    data: geo.SpatialData,
    axes: Axes = None,
    color: Union[int, Tuple[int, int, int], Tuple[float, float, float]] = None,
    label: str = None,
    show_wireframe: bool = True,
) -> Axes:
    """Visualize a `weldx.geometry.SpatialData` instance.

    Parameters
    ----------
    data :
        The data that should be visualized
    axes :
        The target `matplotlib.axes.Axes` object of the plot. If 'None' is passed, a
        new figure will be created
    color :
        A 24 bit integer, a triplet of integers with a value range of 0-255
        or a triplet of floats with a value range of 0.0-1.0 that represent an RGB
        color
    label :
        Label of the plotted geometry
    show_wireframe :
        If `True`, the mesh is plotted as wireframe. Otherwise only the raster
        points are visualized. Currently, the wireframe can't be visualized if a
        `weldx.geometry.VariableProfile` is used.

    Returns
    -------
    matplotlib.axes.Axes :
        The `matplotlib.axes.Axes` instance that was used for the plot.

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

    if not isinstance(data, geo.SpatialData):
        data = geo.SpatialData(data)

    if color is None:
        color = (0.0, 0.0, 0.0)
    else:
        color = color_to_rgb_normalized(color)

    coordinates = data.coordinates.data
    triangles = data.triangles

    # if data is time dependent or has other extra dimensions, just take the first value
    while coordinates.ndim > 2:
        coordinates = coordinates[0]

    axes.scatter(
        coordinates[:, 0],
        coordinates[:, 1],
        coordinates[:, 2],
        marker=".",
        color=color,
        label=label,
        zorder=2,
    )
    if triangles is not None and show_wireframe:
        for triangle in triangles:
            triangle_data = coordinates[[*triangle, triangle[0]], :]
            axes.plot(
                triangle_data[:, 0],
                triangle_data[:, 1],
                triangle_data[:, 2],
                color=color,
                zorder=1,
            )

    return axes
Exemplo n.º 4
0
def plot_spatial_data_matplotlib(
    data: Union[np.ndarray, geo.SpatialData],
    axes: Axes = None,
    color: Union[int, tuple[int, int, int], tuple[float, float, float]] = None,
    label: str = None,
    limits: types_limits = None,
    show_wireframe: bool = True,
) -> Axes:
    """Visualize a `weldx.geometry.SpatialData` instance.

    Parameters
    ----------
    data :
        The data that should be visualized
    axes :
        The target `matplotlib.axes.Axes` object of the plot. If 'None' is passed, a
        new figure will be created
    color :
        A 24 bit integer, a triplet of integers with a value range of 0-255
        or a triplet of floats with a value range of 0.0-1.0 that represent an RGB
        color
    label :
        Label of the plotted geometry
    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.
    show_wireframe :
        If `True`, the mesh is plotted as wireframe. Otherwise only the raster
        points are visualized. Currently, the wireframe can't be visualized if a
        `weldx.geometry.VariableProfile` is used.

    Returns
    -------
    matplotlib.axes.Axes :
        The `matplotlib.axes.Axes` instance that was used for the plot.

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

    if not isinstance(data, geo.SpatialData):
        data = geo.SpatialData(data)

    if color is None:
        color = (0.0, 0.0, 0.0)
    else:
        color = color_to_rgb_normalized(color)

    coordinates = data.coordinates.data
    if isinstance(coordinates, Q_):
        coordinates = coordinates.to(_DEFAULT_LEN_UNIT).m
    coordinates = coordinates.reshape(-1, 3)
    triangles = data.triangles

    # if data is time dependent or has other extra dimensions, just take the first value
    while coordinates.ndim > 2:
        coordinates = coordinates[0]

    axes.scatter(
        coordinates[:, 0],
        coordinates[:, 1],
        coordinates[:, 2],
        marker=".",
        color=color,
        label=label,
        zorder=2,
    )
    if triangles is not None and show_wireframe:
        for triangle in triangles:
            triangle_data = coordinates[[*triangle, triangle[0]], :]
            axes.plot(
                triangle_data[:, 0],
                triangle_data[:, 1],
                triangle_data[:, 2],
                color=color,
                zorder=1,
            )

    _set_limits_matplotlib(axes, limits)
    return axes