예제 #1
0
def matplotlib_plot(scale, cmap, filename=None):

    points = list(ternary.helpers.simplex_iterator(scale))
    xs, ys = zip(*map(project, points))
    values = range(len(points))

    f, axes = plt.subplots(1, 3, figsize=(8.5, 4.5))

    styles = ['triangular', 'dual-triangular', 'hexagonal']
    ticks_list = [range(scale + 1), range(scale + 2), range(scale + 1)]
    shift = True
    for ax, style, ticks in zip(axes, styles, ticks_list):
        ax.set_aspect('equal')
        ax.set_title(style)
        ternary.heatmap(dict(zip(points, values)),
                        scale=scale,
                        ax=ax,
                        cmap=cmap,
                        vmax=len(points) + 1,
                        style=style,
                        colorbar=False)
        if style == 'dual-triangular' and shift:
            xvals = np.array(xs) + .5
            yvals = np.array(ys) + 1 / 3
        else:
            xvals = xs
            yvals = ys

        ax.scatter(xvals, yvals, s=150, c='c', zorder=3)
        ax.set_xticks(ticks)
        ax.set_yticks(ticks)
        for x, y, value in zip(xvals, yvals, values):
            ax.text(x,
                    y,
                    str(value),
                    fontsize=8,
                    horizontalalignment='center',
                    verticalalignment='center')

    # Colorbar
    f.tight_layout()
    cbax = f.add_axes([0.025, 0.1, 0.95, 0.10])
    norm = mpl.colors.Normalize(vmin=0, vmax=len(points))
    ticks = np.linspace(0, len(points), num=len(points) + 1)
    cb1 = mpl.colorbar.ColorbarBase(cbax,
                                    cmap=cmap,
                                    norm=norm,
                                    orientation='horizontal')
    cb1.set_ticks(ticks)

    if filename is not None:
        plt.savefig(filename)

    return ax
예제 #2
0
def matplotlib_plot(scale, cmap, filename=None):

    points = list(ternary.helpers.simplex_iterator(scale))
    xs, ys = zip(*map(project, points))
    values = range(len(points))

    f, axes = plt.subplots(1,3, figsize=(8.5, 4.5))

    styles = ['triangular', 'dual-triangular', 'hexagonal']
    ticks_list = [range(scale + 1), range(scale + 2), range(scale + 1)]
    shift = True
    for ax, style, ticks in zip(axes, styles, ticks_list):
        ax.set_aspect('equal')
        ax.set_title(style)
        ternary.heatmap(dict(zip(points, values)),
                        scale=scale, ax=ax,
                        cmap=cmap, vmax=len(points) + 1,
                        style=style, colorbar=False)
        if style == 'dual-triangular' and shift:
            xvals = np.array(xs) + .5
            yvals = np.array(ys) + 1/3
        else:
            xvals = xs
            yvals = ys

        ax.scatter(xvals, yvals, s=150, c='c', zorder=3)
        ax.set_xticks(ticks)
        ax.set_yticks(ticks)
        for x, y, value in zip(xvals, yvals, values):
            ax.text(x, y, str(value),
                    fontsize=8,
                    horizontalalignment='center',
                    verticalalignment='center')

    # Colorbar
    f.tight_layout()
    cbax = f.add_axes([0.025, 0.1, 0.95, 0.10])
    norm = mpl.colors.Normalize(vmin=0, vmax=len(points))
    ticks = np.linspace(0, len(points), num=len(points) + 1)
    cb1 = mpl.colorbar.ColorbarBase(cbax, cmap=cmap,
                                    norm=norm,
                                    orientation='horizontal')
    cb1.set_ticks(ticks)

    if filename is not None:
        plt.savefig(filename)

    return ax
예제 #3
0
def tournament_stationary_3(N, mu=None):
    """
    Example for a tournament selection matrix.
    """

    if not mu:
        mu = 3./2 * 1./N
    m = [[1,1,1], [0,1,1], [0,0,1]]
    num_types = len(m[0])
    fitness_landscape = linear_fitness_landscape(m)
    incentive = replicator(fitness_landscape)
    edges = incentive_process.multivariate_transitions(N, incentive, num_types=num_types, mu=mu)
    s = stationary_distribution(edges)
    ternary.heatmap(s, scale=N, scientific=True)
    d = expected_divergence(edges, q_d=0)
    ternary.heatmap(d, scale=N, scientific=True)
    pyplot.show()
예제 #4
0
def tournament_stationary_3(N, mu=None):
    """
    Example for a tournament selection matrix.
    """

    if not mu:
        mu = 3. / 2 * 1. / N
    m = [[1, 1, 1], [0, 1, 1], [0, 0, 1]]
    num_types = len(m[0])
    fitness_landscape = linear_fitness_landscape(m)
    incentive = replicator(fitness_landscape)
    edges = incentive_process.multivariate_transitions(N,
                                                       incentive,
                                                       num_types=num_types,
                                                       mu=mu)
    s = stationary_distribution(edges)
    ternary.heatmap(s, scale=N, scientific=True)
    d = expected_divergence(edges, q_d=0)
    ternary.heatmap(d, scale=N, scientific=True)
    pyplot.show()