Пример #1
0
def _set_legend(labels: np.ndarray, cmap: colors.ListedColormap, ax: plt.Subplot):
    unique_labels = np.unique(labels)
    legend_elements = [Patch(facecolor=cmap.colors[i], label=unique_label)
                       for i, unique_label in enumerate(unique_labels)]
    legend = ax.legend(handles=legend_elements, title='Clusters', fontsize=14,
                       title_fontsize=14, loc="lower left")
    legend.get_frame().set_alpha(None)
    legend.get_frame().set_facecolor((1, 1, 1, 0.25))
Пример #2
0
def plot_stop_accessibility_cdf(subplot: Subplot, result: CrossStopRemovalResult):
    """Plot the accessibility difference in ``result`` as a subplot onto ``subplot``."""
    # pylint: disable=invalid-name

    # Configure plot
    subplot.set_xlabel("Distance to stop (km)", size=20)
    subplot.set_ylabel("Percentile", size=20)
    subplot.set_title(result.stop_removed.cross_name, size=24)

    # Plot CDF
    x, y = result.metrics_before.get_quantile_cdf(20)
    subplot.plot(x, y, label="Before")

    x, y = result.metrics_after.get_quantile_cdf(20)
    subplot.plot(x, y, label="After")

    # Post-configure the plot
    subplot.legend(loc="upper right")
Пример #3
0
def plot_stop_accessibility_hist(subplot: Subplot,
                                 result: CrossStopRemovalResult):
    """Plot the accessibility difference in ``result`` as a subplot onto ``subplot``."""
    # ----- Plot histogram
    # https://datavizpyr.com/overlapping-histograms-with-matplotlib-in-python/

    # Configure plot
    subplot.set_xlabel("Distance to stop (km)", size=14)
    subplot.set_ylabel("Agent count", size=14)
    subplot.set_title(
        f"Distance to stop between before and after removing {result.stop_removed.cross_name}"
    )

    # Plot histograms
    subplot.hist(result.metrics_before.data,
                 bins=20,
                 alpha=0.5,
                 label="Before")
    subplot.hist(result.metrics_after.data, bins=20, alpha=0.5, label="After")

    # Post-configure the plot
    subplot.legend(loc="upper right")
Пример #4
0
def add_proportion(ax1: plt.Subplot, ax2: plt.Subplot, series: pd.Series,
                   name: str) -> list:

    for key in series.keys():
        if series[key] < .05 * sum(series):
            if 'other' not in series.keys():
                series['other'] = 0

            series['other'] += series.pop(key)

    wedges, _, autotexts = ax2.pie(series.values,
                                   autopct='%1.1f%%',
                                   startangle=90,
                                   colors=COLORS,
                                   counterclock=False)

    ax1.legend(wedges, series.keys(), title=name, loc="center")

    ax2.axis('equal')
    ax1.axis('off')

    return autotexts