def basic_example(): # Projection dynamic. initial_state = normalize(numpy.array([1,1,4])) m = rock_scissors_paper(a=1., b=-2.) fitness = linear_fitness(m) incentive = replicator_incentive_power(fitness, 0) mu = uniform_mutation_matrix(3, ep=0.2) t = compute_trajectory(initial_state, incentive, escort=power_escort(0), iterations=10000, verbose=True, mu=mu) ternary.plot(t, linewidth=2) ternary.draw_boundary() ## Lyapunov Quantities pyplot.figure() # Replicator Lyapunov e = normalize(numpy.array([1,1,1])) v = [kl_divergence(e, x) for x in t] pyplot.plot(range(len(t)), v, color='b') d = q_divergence(0) v = [d(e, x) for x in t] pyplot.plot(range(len(t)), v, color='r') pyplot.show()
c = gray d = vp endmembers = ('Granite Gneiss', 'Mafic Granulite', 'Gray Gneiss') datalabels = ['Vp',r'$\sigma$'] colors = ['b','g','c','m','r'] lines = terntransform(a, b, c, d) step = 0.2 plt.figure() for line,color,label in zip(lines,colors,datalabels): tern.plot(line, color = color, linewidth=2.0, label = label) ip = baryIntersect(lines) tern.plotIntersect(ip) tern.gridlines(step, '0.7') tern.draw_boundary() tern.addlabels(endmembers) plt.legend() #pyplot.box(on='off') h = plt.gca() #plt.axis('off') xmin = -0.1 xmax = 1.1 ymin = -0.1
# Data plt.figure() for ind, region in enumerate(regions): data = lithdata[3:6] data.append(region[1]) datalabels = ['Vp',r'$\sigma$'] colors = ['b','g','c','m','r','y'] lines = terntransform( *data ) for line, color, label in zip(lines, colors, datalabels): tern.plot(line, color = color, linewidth=2.0, label = label if (ind == 0) else None) ip = baryIntersect(lines) tern.plotIntersect(ip, marker = 'o'+colors[ind], label = region[0]) step = 0.2 tern.gridlines(step, '0.7') tern.draw_boundary() tern.addlabels(endmembers) plt.legend() #pyplot.box(on='off') h = plt.gca() #plt.axis('off') xmin = -0.1 xmax = 1.1
"""Plot an empty heatmap shell for illustration.""" for i in range(steps + 1): for j in range(steps - i): vertices = ternary.triangle_coordinates(i, j, alt=False) x, y = ternary.unzip(vertices) pyplot.fill(x, y, facecolor=fill_color, edgecolor="black") for i in range(steps + 1): for j in range(steps - i - 1): vertices = ternary.triangle_coordinates(i, j, alt=True) x, y = ternary.unzip(vertices) pyplot.fill(x, y, facecolor="w", edgecolor="black") ternary.draw_boundary(scale=steps, linewidth=1) if __name__ == "__main__": pyplot.figure() plot_shell(16) pyplot.figure() heatmap_example(shannon_entropy, steps=100, boundary=True) pyplot.figure() func = dirichlet([6, 10, 13]) heatmap_example(func, steps=100, boundary=False) pyplot.figure() points = [] with open("curve.txt") as handle: for line in handle: points.append(map(float, line.split(" "))) ternary.plot(points, linewidth=2.0) ternary.draw_boundary() pyplot.show()
ternary.draw_boundary(steps+1, ax=ax, color='black') ax.set_title("Triangular with Boundary") ax = pyplot.subplot(gs[0,1]) ternary.function_heatmap(function, steps=steps, boundary_points=False, ax=ax) ternary.draw_boundary(steps+1, ax=ax, color='black') ax.set_title("Triangular without Boundary") ax = pyplot.subplot(gs[1,0]) ternary.function_heatmap(function, steps=steps, boundary_points=True, ax=ax, style="hexagonal") ternary.draw_boundary(steps, ax=ax, color='black') ax.set_title("Hexagonal with Boundary") ax = pyplot.subplot(gs[1,1]) ternary.function_heatmap(function, steps=steps, boundary_points=False, ax=ax, style="hexagonal") ternary.draw_boundary(steps, ax=ax, color='black') ax.set_title("Hexagonal without Boundary") ## Sample trajectory plot pyplot.figure() ax = ternary.draw_boundary(color='black') ax.set_title("Plotting of sample trajectory data") points = [] with open("curve.txt") as handle: for line in handle: points.append(map(float, line.split(' '))) ternary.plot(points, linewidth=2.0, ax=ax) pyplot.show()
# Data plt.figure() for ind, region in enumerate(regions): data = lithdata[3:6] data.append(region[1]) datalabels = ['Vp', r'$\sigma$'] colors = ['b', 'g', 'c', 'm', 'r', 'y'] lines = terntransform(*data) for line, color, label in zip(lines, colors, datalabels): tern.plot(line, color=color, linewidth=2.0, label=label if (ind == 0) else None) ip = baryIntersect(lines) tern.plotIntersect(ip, marker='o' + colors[ind], label=region[0]) step = 0.2 tern.gridlines(step, '0.7') tern.draw_boundary() tern.addlabels(endmembers) plt.legend() #pyplot.box(on='off') h = plt.gca() #plt.axis('off') xmin = -0.1