예제 #1
0
    def _payoff_heatmap(
            self,
            data: dataType,
            names: namesType,
            title: titleType = None,
            ax: matplotlib.axes.SubplotBase = None
    ) -> matplotlib.figure.Figure:
        """Generic heatmap plot"""

        if ax is None:
            _, ax = plt.subplots()
        else:
            ax = ax

        figure = ax.get_figure()
        width = max(self.nplayers / 4, 12)
        height = width
        figure.set_size_inches(width, height)
        matplotlib_version = matplotlib.__version__
        cmap = default_cmap(matplotlib_version)
        mat = ax.matshow(data, cmap=cmap)
        ax.set_xticks(range(self.result_set.nplayers))
        ax.set_yticks(range(self.result_set.nplayers))
        ax.set_xticklabels(names, rotation=90)
        ax.set_yticklabels(names)
        ax.tick_params(axis='both', which='both', labelsize=16)
        if title:
            ax.set_xlabel(title)
        figure.colorbar(mat, ax=ax)
        plt.tight_layout()
        return figure
예제 #2
0
파일: plot.py 프로젝트: Nikoleta-v3/Axelrod
    def _payoff_heatmap(
        self,
        data: dataType,
        names: namesType,
        title: titleType = None,
        ax: matplotlib.axes.SubplotBase = None,
    ) -> matplotlib.figure.Figure:
        """Generic heatmap plot"""

        if ax is None:
            _, ax = plt.subplots()
        else:
            ax = ax

        figure = ax.get_figure()
        width = max(self.num_players / 4, 12)
        height = width
        figure.set_size_inches(width, height)
        matplotlib_version = matplotlib.__version__
        cmap = default_cmap(matplotlib_version)
        mat = ax.matshow(data, cmap=cmap)
        ax.set_xticks(range(self.result_set.num_players))
        ax.set_yticks(range(self.result_set.num_players))
        ax.set_xticklabels(names, rotation=90)
        ax.set_yticklabels(names)
        ax.tick_params(axis="both", which="both", labelsize=16)
        if title:
            ax.set_xlabel(title)
        figure.colorbar(mat, ax=ax)
        plt.tight_layout()
        return figure
예제 #3
0
    def stackplot(
        self,
        eco,
        title: titleType = None,
        logscale: bool = True,
        ax: matplotlib.axes.SubplotBase = None,
    ) -> matplotlib.figure.Figure:

        populations = eco.population_sizes

        if ax is None:
            _, ax = plt.subplots()
        else:
            ax = ax

        figure = ax.get_figure()
        turns = range(len(populations))
        pops = [
            [populations[iturn][ir] for iturn in turns]
            for ir in self.result_set.ranking
        ]
        ax.stackplot(turns, *pops)

        ax.yaxis.tick_left()
        ax.yaxis.set_label_position("right")
        ax.yaxis.labelpad = 25.0

        ax.set_ylim([0.0, 1.0])
        ax.set_ylabel("Relative population size")
        ax.set_xlabel("Turn")
        if title is not None:
            ax.set_title(title)

        trans = transforms.blended_transform_factory(ax.transAxes, ax.transData)
        ticks = []
        for i, n in enumerate(self.result_set.ranked_names):
            x = -0.01
            y = (i + 0.5) * 1 / self.result_set.num_players
            ax.annotate(
                n,
                xy=(x, y),
                xycoords=trans,
                clip_on=False,
                va="center",
                ha="right",
                fontsize=5,
            )
            ticks.append(y)
        ax.set_yticks(ticks)
        ax.tick_params(direction="out")
        ax.set_yticklabels([])

        if logscale:
            ax.set_xscale("log")

        plt.tight_layout()
        return figure
예제 #4
0
파일: plot.py 프로젝트: Nikoleta-v3/Axelrod
    def stackplot(
        self,
        eco,
        title: titleType = None,
        logscale: bool = True,
        ax: matplotlib.axes.SubplotBase = None,
    ) -> matplotlib.figure.Figure:

        populations = eco.population_sizes

        if ax is None:
            _, ax = plt.subplots()
        else:
            ax = ax

        figure = ax.get_figure()
        turns = range(len(populations))
        pops = [
            [populations[iturn][ir] for iturn in turns]
            for ir in self.result_set.ranking
        ]
        ax.stackplot(turns, *pops)

        ax.yaxis.tick_left()
        ax.yaxis.set_label_position("right")
        ax.yaxis.labelpad = 25.0

        ax.set_ylim([0.0, 1.0])
        ax.set_ylabel("Relative population size")
        ax.set_xlabel("Turn")
        if title is not None:
            ax.set_title(title)

        trans = transforms.blended_transform_factory(ax.transAxes, ax.transData)
        ticks = []
        for i, n in enumerate(self.result_set.ranked_names):
            x = -0.01
            y = (i + 0.5) * 1 / self.result_set.num_players
            ax.annotate(
                n,
                xy=(x, y),
                xycoords=trans,
                clip_on=False,
                va="center",
                ha="right",
                fontsize=5,
            )
            ticks.append(y)
        ax.set_yticks(ticks)
        ax.tick_params(direction="out")
        ax.set_yticklabels([])

        if logscale:
            ax.set_xscale("log")

        plt.tight_layout()
        return figure
예제 #5
0
 def plot_2_1_ci(ax: matplotlib.axes.SubplotBase, df_pred_str: pd.DataFrame, df_pred_str_null: pd.DataFrame,
                 rows_set: np.ndarray) -> None:
     mu, sigma = ClusteringUtils.calc_distribution(df_pred_str.loc[rows_set])
     mu_null, sigma_null = ClusteringUtils.calc_distribution(df_pred_str_null.loc[rows_set])
     y = pd.DataFrame([
         mu - sigma > mu_null + sigma_null
     ])
     ax.imshow(y)
     ax.set_xlabel("k")
     ax.set_ylabel("CI intersection")
     ax.set_yticks([])
     ax.xaxis.set_major_locator(ticker.FixedLocator((np.arange(len(y.columns)))))
     ax.xaxis.set_major_formatter(ticker.FixedFormatter(y.columns))