Esempio n. 1
0
    def geometric_realization(self, dim: int, ax: Axes) -> None:
        """
        Draw simplices of one dimension.
        
        Args:
            dim (int): simplex dimension
            ax (matplotlib.axes.Axes): axes to draw on
        
        Returns:
            None
        """
        if dim > self.simplex_dim:
            raise ValueError(
                f"Dimensionality is too high: max dim for this complex is {self.simplex_dim} but got {dim} as dim"
            )

        ax.set_xlim(self.vertices[:, 0].min() - 1,
                    self.vertices[:, 0].max() + 1)
        ax.set_ylim(self.vertices[:, 1].min() - 1,
                    self.vertices[:, 1].max() + 1)

        if dim == 0:  # points
            ax.scatter(self.vertices[:, 0], self.vertices[:, 1])
            return

        coords = [
            self._simplex_to_point_set(simplex)
            for simplex in self.simplices[dim]
        ]
        if dim == 1:  # edges
            ax.add_collection(LineCollection(coords))
        else:  # volumes
            for polygon in coords:
                ax.fill(polygon[:, 0], polygon[:, 1], color=(0, 0, 1, 0.1))
Esempio n. 2
0
def plot_polygon(
    geometry: Union[Polygon, MultiPolygon],
    fill: bool = False,
    axis: Axes = None,
    show: bool = False,
    **kwargs,
) -> Axes:
    """
    Plot the given polygon.

    :param geometry: Shapely polygon (or multipolygon)
    :param axis: `pyplot` axis to plot to
    :param show:  whether to show the plot
    """

    if axis is None:
        axis = pyplot.gca()

    if 'c' not in kwargs:
        try:
            color = next(axis._get_lines.color_cycle)
        except AttributeError:
            color = 'r'
        kwargs['c'] = color

    if isinstance(geometry, dict):
        geometry = shapely_shape(geometry)

    if type(geometry) is Polygon:
        if fill:
            axis.fill(*geometry.exterior.xy, **kwargs)
            kwargs['c'] = 'w'
            for interior in geometry.interiors:
                axis.fill(*interior.xy, **kwargs)
        else:
            axis.plot(*geometry.exterior.xy, **kwargs)
            for interior in geometry.interiors:
                axis.plot(*interior.xy, **kwargs)
    elif type(geometry) is MultiPolygon:
        for polygon in geometry:
            plot_polygon(geometry=polygon,
                         axis=axis,
                         fill=fill,
                         show=False,
                         **kwargs)
    else:
        if fill:
            axis.fill(*geometry.xy, **kwargs)
        else:
            axis.plot(*geometry.xy, **kwargs)

    if show:
        pyplot.show()

    return axis
Esempio n. 3
0
def create_spider_chart_plot(
    axis: Axes,
    data_to_plot: dict,
    categories: List[str],
    accept_classes: List[str],
):
    """Creates spider-chart with ``categories`` for all classes in ``accept_classes``.

    Args:
        axis (Axes): Axes-instances to use for the spider-chart
        data_to_plot (dict): Dictionary containing ``categories`` as keys.
        categories (list of str): List of category-names to use for the spider-chart.
        accept_classes (list of str): List of class-names to use for the spider-chart.
    """

    # create labels
    lables = [category.replace("_", "-") for category in categories]

    # Calculate metrics for each class
    vals = {
        cat: [
            cat_vals["auc"] for x, cat_vals in data_to_plot[cat].items()
            if x in accept_classes
        ]
        for cat in categories
    }

    # norm everything to AP
    for key in ["Center_Dist", "Size_Similarity", "OS_Yaw", "OS_Pitch_Roll"]:
        vals[key] = [v * float(ap) for (v, ap) in zip(vals[key], vals["AP"])]

    # setup axis
    num_categories = len(categories)

    angles = [
        n / float(num_categories) * 2 * np.pi for n in range(num_categories)
    ]
    angles += angles[:1]

    axis.set_theta_offset(np.pi / 2.)
    axis.set_theta_direction(-1)
    axis.set_rlabel_position(0)
    axis.set_yticks([0.25, 0.50, 0.75])
    axis.set_yticklabels(["0.25", "0.50", "0.75"], color="grey", size=7)
    axis.tick_params(axis="x", direction="out", pad=10)
    axis.set_ylim([0, 1])
    axis.set_xticks(np.arange(0, 2.0 * np.pi, np.pi / 2.5))
    axis.set_xticklabels(lables)

    for idx, class_name in enumerate(accept_classes):
        values = [x[idx] for x in [vals[cat] for cat in categories]]
        values += values[:1]

        axis.plot(angles,
                  values,
                  linewidth=1,
                  linestyle='solid',
                  color=csToMplColor(class_name))
        axis.fill(angles, values, color=csToMplColor(class_name), alpha=0.05)

    axis.plot(
        angles,
        [np.mean(x) for x in [vals[cat] for cat in categories] + [vals["AP"]]],
        linewidth=1,
        linestyle='solid',
        color="r",
        label="Mean")
    axis.legend(bbox_to_anchor=(0, 0))