def curvelinear_test1(fig): """ grid for custom transform. """ def tr(x, y): x, y = np.asarray(x), np.asarray(y) return x, y-x def inv_tr(x,y): x, y = np.asarray(x), np.asarray(y) return x, y+x grid_helper = GridHelperCurveLinear((tr, inv_tr)) ax1 = Subplot(fig, 1, 2, 1, grid_helper=grid_helper) # ax1 will have a ticks and gridlines defined by the given # transform (+ transData of the Axes). Note that the transform of # the Axes itself (i.e., transData) is not affected by the given # transform. fig.add_subplot(ax1) xx, yy = tr([3, 6], [5.0, 10.]) ax1.plot(xx, yy) ax1.set_aspect(1.) ax1.set_xlim(0, 10.) ax1.set_ylim(0, 10.) ax1.axis["t"]=ax1.new_floating_axis(0, 3.) ax1.axis["t2"]=ax1.new_floating_axis(1, 7.) ax1.grid(True)
def curvelinear_test1(fig): """ grid for custom transform. """ def tr(x, y): x, y = np.asarray(x), np.asarray(y) return x, y - x def inv_tr(x, y): x, y = np.asarray(x), np.asarray(y) return x, y + x grid_helper = GridHelperCurveLinear((tr, inv_tr)) ax1 = Subplot(fig, 1, 2, 1, grid_helper=grid_helper) # ax1 will have a ticks and gridlines defined by the given # transform (+ transData of the Axes). Note that the transform of # the Axes itself (i.e., transData) is not affected by the given # transform. fig.add_subplot(ax1) xx, yy = tr([3, 6], [5.0, 10.]) ax1.plot(xx, yy) ax1.set_aspect(1.) ax1.set_xlim(0, 10.) ax1.set_ylim(0, 10.) ax1.grid(True)
def curvelinear_test1(fig): """ grid for custom transform. """ def tr(x, y): x, y = np.asarray(x), np.asarray(y) return x, y-x def inv_tr(x,y): x, y = np.asarray(x), np.asarray(y) return x, y+x grid_helper = GridHelperCurveLinear((tr, inv_tr)) ax1 = Subplot(fig, 1, 2, 1, grid_helper=grid_helper) fig.add_subplot(ax1) xx, yy = tr([3, 6], [5.0, 10.]) ax1.plot(xx, yy) ax1.set_aspect(1.) ax1.set_xlim(0, 10.) ax1.set_ylim(0, 10.) ax1.grid(True)
def generate_graph(chromosome, nearest_supers, FIELD_WIDTH, FIELD_HEIGHT, graph_title, n): chromosome = [int(i) for i in chromosome] w = (FIELD_WIDTH) / 4.0 h = (FIELD_HEIGHT) / 4.0 fig = pylab.figure(figsize=(w + 1, h)) #fig = pylab.figure(figsize=(2.5,3)) #ax = pylab.subplot(111) ax = Subplot(fig, 111) fig.add_subplot(ax) #ax.axis["right"].set_visible(False) #ax.axis["top"].set_visible(False) #ax.axis["bottom"].set_visible(False) #ax.axis["left"].set_visible(False) super_x = [ coords[i][0] for i in range(len(chromosome)) if (chromosome[i] == 1) ] super_y = [ coords[i][1] for i in range(len(chromosome)) if chromosome[i] == 1 ] sensor_x = [ coords[i][0] for i in range(len(chromosome)) if chromosome[i] == 0 ] sensor_y = [ coords[i][1] for i in range(len(chromosome)) if chromosome[i] == 0 ] target_x = 0 target_y = 0 #pylab.grid(True) for i, node in enumerate(chromosome): if node == 1: ax.plot([coords[i][0], 0], [coords[i][1], 0], '--', lw=.85, color='red') if not node and nearest_supers[i] >= 0: ax.plot([coords[i][0], coords[nearest_supers[i]][0]], [coords[i][1], coords[nearest_supers[i]][1]], '-', lw=.85, color='blue') ax.plot(sensor_x, sensor_y, 'go', label=r'sensor') ax.plot(super_x, super_y, 'bo', label=r'super') ax.plot(target_x, target_y, 'ro', label=r'target') #add_ranges(ax, chromosome) #draw_clusters(ax, chromosome, nearest_supers) pylab.xticks(pylab.arange(0, FIELD_WIDTH + 1, 1), color='white') pylab.yticks(pylab.arange(0, FIELD_HEIGHT + 1, 1), color='white') #ax.set_xticklabels([]) #ax.set_yticklabels([]) #pylab.title(graph_title) pylab.xlim((-1, FIELD_WIDTH + 1)) pylab.ylim((-1, FIELD_HEIGHT + 1)) ax.set_aspect(1) #legend(loc='right', bbox_to_anchor=(2,1)) #box = ax.get_position() #ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) #ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) #box = ax.get_position() #ax.set_position([box.x0, box.y0 + box.height * 0.1, # box.width, box.height * 0.9]) #ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), # fancybox=True, shadow=True, ncol=5,numpoints=1) #LEGEND #box = ax.get_position() #ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) #ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), numpoints=1) filename = "/home/milleraj/Desktop/genetic_graphs/chrom%d.pdf" % n print filename pylab.savefig(filename)
def generate_graph(chromosome, nearest_supers, FIELD_WIDTH, FIELD_HEIGHT, graph_title, n): chromosome = [ int(i) for i in chromosome ] w = (FIELD_WIDTH)/4.0 h = (FIELD_HEIGHT)/4.0 fig = pylab.figure(figsize=(w+1,h)) #fig = pylab.figure(figsize=(2.5,3)) #ax = pylab.subplot(111) ax = Subplot(fig, 111) fig.add_subplot(ax) #ax.axis["right"].set_visible(False) #ax.axis["top"].set_visible(False) #ax.axis["bottom"].set_visible(False) #ax.axis["left"].set_visible(False) super_x = [ coords[i][0] for i in range(len(chromosome)) if (chromosome[i] == 1) ] super_y = [ coords[i][1] for i in range(len(chromosome)) if chromosome[i] == 1 ] sensor_x = [ coords[i][0] for i in range(len(chromosome)) if chromosome[i] == 0 ] sensor_y = [ coords[i][1] for i in range(len(chromosome)) if chromosome[i] == 0 ] target_x = 0 target_y = 0 #pylab.grid(True) for i, node in enumerate(chromosome): if node == 1: ax.plot([coords[i][0], 0], [coords[i][1], 0], '--',lw=.85, color='red') if not node and nearest_supers[i] >= 0: ax.plot([coords[i][0], coords[nearest_supers[i]][0]], [coords[i][1], coords[nearest_supers[i]][1]], '-', lw=.85, color='blue') ax.plot(sensor_x, sensor_y, 'go', label=r'sensor') ax.plot(super_x, super_y, 'bo', label=r'super') ax.plot(target_x, target_y, 'ro', label=r'target') #add_ranges(ax, chromosome) #draw_clusters(ax, chromosome, nearest_supers) pylab.xticks(pylab.arange(0, FIELD_WIDTH+1, 1), color='white') pylab.yticks(pylab.arange(0, FIELD_HEIGHT+1, 1), color='white') #ax.set_xticklabels([]) #ax.set_yticklabels([]) #pylab.title(graph_title) pylab.xlim((-1, FIELD_WIDTH+1)) pylab.ylim((-1, FIELD_HEIGHT+1)) ax.set_aspect(1) #legend(loc='right', bbox_to_anchor=(2,1)) #box = ax.get_position() #ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) #ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) #box = ax.get_position() #ax.set_position([box.x0, box.y0 + box.height * 0.1, # box.width, box.height * 0.9]) #ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), # fancybox=True, shadow=True, ncol=5,numpoints=1) #LEGEND #box = ax.get_position() #ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) #ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), numpoints=1) filename = "/home/milleraj/Desktop/genetic_graphs/chrom%d.pdf" % n print filename pylab.savefig(filename)