def standard_axis(fig, subplot, sharex=None, sharey=None, hasx=False, hasy=True): sys.stderr.write("This method is deprecated. " "Use stfio_plot.StandardAxis instead.\n") try: iter(subplot) if isinstance(subplot, matplotlib.gridspec.GridSpec): ax1 = Subplot( fig, subplot, frameon=False, sharex=sharex, sharey=sharey) else: ax1 = Subplot( fig, subplot[0], subplot[1], subplot[2], frameon=False, sharex=sharex, sharey=sharey) except: ax1 = Subplot( fig, subplot, frameon=False, sharex=sharex, sharey=sharey) fig.add_axes(ax1) ax1.axis["right"].set_visible(False) ax1.axis["top"].set_visible(False) if not hasx: ax1.axis["bottom"].set_visible(False) if not hasy: ax1.axis["left"].set_visible(False) return ax1
def Recip_space(sample): """ Set up general reciprocal space grid for plotting Miller indicies in a general space. Would be cool if returned fig object had a custom transformation so that all data added to plot after it has been created can be given in miller indicies 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)) fig = plt.figure(1, figsize=(7, 4)) ax = Subplot(fig, 1, 1, 1, grid_helper=grid_helper) rlatt = sample.star_lattice [xs, ys, zs] = sample.StandardSystem fig.add_subplot(ax) ax.grid(True) return
def curvelinear_test1(fig): """ grid for custom transform. """ def tr(x, y): sgn = np.sign(x) x, y = np.abs(np.asarray(x)), np.asarray(y) return sgn*x**.5, y def inv_tr(x,y): sgn = np.sign(x) x, y = np.asarray(x), np.asarray(y) return sgn*x**2, y extreme_finder = angle_helper.ExtremeFinderCycle(20, 20, lon_cycle = None, lat_cycle = None, lon_minmax = None, #(0, np.inf), lat_minmax = None, ) grid_helper = GridHelperCurveLinear((tr, inv_tr), extreme_finder=extreme_finder) ax1 = Subplot(fig, 111, grid_helper=grid_helper) fig.add_subplot(ax1) ax1.imshow(np.arange(25).reshape(5,5), vmax = 50, cmap=plt.cm.gray_r, interpolation="nearest", origin="lower") grid_helper.grid_finder.grid_locator1._nbins = 6 grid_helper.grid_finder.grid_locator2._nbins = 6
def plot_bars(bar_list, tick_labels, tick_positions=None, x_label='', y_label='', title='', legend_names=[], loc=2): # plot values fig = plt.figure() fig.suptitle(title) ax = Subplot(fig, 111) ax = fig.add_subplot(ax) plt.ylabel(y_label) plt.xlabel(x_label) # plot each dataset width = .9/len(bar_list) # the width of the bars ind = np.array(range(len(bar_list[0]))) color_list = ['#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c', '#fdbf6f', '#ff7f00', '#cab2d6', '#6a3d9a', '#ffff99', '#b15928'] recs = [] for i in range(len(bar_list)): recs.append(ax.bar(ind + (width * i), bar_list[i], width, color=color_list[i], linewidth=0)) # calculate where the labels should go if tick_positions is not None: ax.set_xticks(np.array(tick_positions) + .5) else: ax.set_xticks(ind + .5) xtickNames = ax.set_xticklabels(tick_labels) # adjust how the axis shows ax.axis["bottom"].major_ticklabels.set_pad(30) ax.axis["bottom"].label.set_pad(20) ax.axis["bottom"].major_ticklabels.set_rotation(30) ax.axis["bottom"].major_ticks.set_visible(False) ax.axis["top"].set_visible(False) # add a legend if len(legend_names) == len(recs): legend_names = tuple([ln.title() for ln in legend_names]) legend_colors = tuple(r[0] for r in recs) ax.legend( legend_colors, legend_names, frameon=False, loc=loc ) plt.gcf().subplots_adjust(bottom=0.19) # adjust the bottom of the plot plt.show()
def scatter_plots(gmns=[],gms=[],matt=[],average=False, avmatt=False): ''' will plot to scatters of the RMSDs of GMnoscaled vs GMscaled and GMnoscaled vs MATT ''' if gms: r,pval=pearsonr(gmns,gms) line=r''' $r$=%.2f, pval=%.4f $R^2$=%.2f'''%(r,pval,r**2) fig = plt.figure() ax = Subplot(fig, 1,1,1) fig.add_subplot(ax) ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) ax.axis([min(gmns), max(gmns)+0.5,min(gms),max(gms)+0.5]) plt.plot(range(int(max(gmns))+3),'r') plt.scatter(gmns,gms) ax.annotate(line,xy=(min(gmns)+0.5,max(gms)), xytext=(min(gmns)+0.5,max(gms))) if avmatt: plt.xlabel("Average Procrustes RMSD without scaling") plt.ylabel("Average Procrustes RMSD with scaling") plt.savefig('AvGMnsvsAvGMs.png') else: plt.xlabel("Procrustes RMSD without scaling") plt.ylabel("Procrustes RMSD with scaling") plt.savefig('GMnsvsGMs.png')#, transparent=True) r,pval=pearsonr(gmns,gms) line=r''' $r$=%.2f, pval=%.4f $R^2$=%.2f'''%(r,pval,r**2) fig2 = plt.figure() ax2 = Subplot(fig2, 1,1,1) fig2.add_subplot(ax2) ax2.axis["right"].set_visible(False) ax2.axis["top"].set_visible(False) ax2.axis([min(matt),max(matt)+0.5, min(gmns), max(gmns)+0.5]) plt.plot(range(int(max(gmns))+3),'r') plt.scatter(matt,gmns) ax2.annotate(line,xy=(min(gmns)+0.5,max(gms)), xytext=(min(gmns)+0.5,max(gms))) if average: plt.xlabel("Number of Core residues") plt.ylabel("Difference of average RMSD (mean(MATT) - mean(procrustes))") plt.savefig('diffvscore.png') elif avmatt: plt.xlabel("Average MATT RMSD") plt.ylabel("Average Procrustes RMSD without scaling") plt.savefig('AvMATTvsAvgmns.png') else: plt.xlabel("MATT alignment RMSD") plt.ylabel("Procrustes RMSD without scaling") plt.savefig('MattvsGMns.png')#, transparent=True)
def write_legend(data, figsize, mind, maxd, redblue, num_yrs, ylabel, xlabel, facecolor='0.8', linewidth=1.): """Write tiny legend to be plotted on map """ from matplotlib import pyplot as plt figleg = plt.figure(figsize=figsize) axleg = Subplot(figleg, 111) figleg.add_subplot(axleg) axleg.axis['top'].set_visible(False) axleg.axis['bottom'].set_visible(False) axleg.axis['right'].set_visible(False) yloc = plt.MaxNLocator(5) axleg.yaxis.set_major_locator(yloc) plt.ylim((mind, maxd)) plt.fill_between(range(num_yrs), 0., data, where=data >= 0., facecolor=redblue[0], lw=0, alpha=0.95) plt.fill_between(range(num_yrs), 0., data, where=data <= 0., facecolor=redblue[1], lw=0, alpha=0.95) font = {'size': '6'} mpl.rc('font', **font) plt.ylabel(ylabel, fontsize=6) axleg.text(-30., mind * 1.5, xlabel, fontsize=6, verticalalignment='top') plt.savefig('tinyfig' + '12' + '.png', format="png", dpi=300, bbox_inches='tight', transparent=True) plt.close() mpl.rcdefaults() return
def draw_Vollmer(self): self.plotFigure.clf() fontsize = self.settings.general_settings['fontsize'] self.plotaxes = axes = Subplot(self.plotFigure, 111, clip_on='True',\ xlim=(-0.1,1.05), ylim=(-0.1,1.05), autoscale_on='True',\ label='vollmer', aspect='equal', adjustable='box', anchor='SW') self.plotFigure.add_subplot(axes) self.plotaxes.format_coord = self.read_vollmer axes.axis['right'].set_visible(False) axes.axis['top'].set_visible(False) axes.axis['bottom'].set_visible(False) axes.axis['left'].set_visible(False) tr1 = Line2D((0, 1), (0, 0), c='black') axes.add_line(tr1) tr2 = Line2D((0, 0.5), (0, sqrt3_2), c='black') axes.add_line(tr2) tr3 = Line2D((1, 0.5), (0, sqrt3_2), c='black') axes.add_line(tr3) for i in [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]: diag = Line2D((i / 2, 1.0 - i / 2), (sqrt3_2 * i, sqrt3_2 * i), c='grey', lw=0.5) axes.add_line(diag) diag2 = Line2D((i / 2, i), (sqrt3_2 * i, 0), c='grey', lw=0.5) axes.add_line(diag2) diag3 = Line2D((i, i + (1 - i) / 2), (0, sqrt3_2 - sqrt3_2 * i), c='grey', lw=0.5) axes.add_line(diag3) axes.text(-0.08,-0.05,'Point',family='sans-serif',\ size=fontsize,horizontalalignment='left' ) axes.text(0.97,-0.05,'Girdle',family='sans-serif',\ size=fontsize,horizontalalignment='left' ) axes.text(0.5,0.88,'Random',family='sans-serif',\ size=fontsize,horizontalalignment='center' ) for i in [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]: axes.text((1-i)/2, sqrt3_2*(1-i)-0.01, '%d' % (i*100), \ family='sans-serif', size=fontsize, \ horizontalalignment='right', color='grey', rotation='60') axes.text(i, -0.02,'%d' % (i*100), family='sans-serif', \ size=fontsize, horizontalalignment='center', \ verticalalignment='top', color='grey') axes.text(1.0-i/2, sqrt3_2*i-0.01,'%d' % (i*100) , \ family='sans-serif', size=fontsize, \ horizontalalignment='left', color='grey', rotation='-60') for plot_item in self.plot_list: x = plot_item.G + (plot_item.R / 2.) y = plot_item.R * sqrt3_2 element, = axes.plot(x, y, linestyle='',\ **plot_item.point_settings) if plot_item.legend: self.legend_items.append((element, plot_item.legend_text)) axes.set_xlim(-0.1, 1.05) axes.set_ylim(-0.1, 1.05)
def draw_one_attribute_histogram(shp_file,field_name,attribute, output,color='grey',hatch=""): """ draw the figure of one attribute's histograms Args: shp_file: shape file path attribute_name: name of attribute output: output the figure Returns: True if successful, False otherwise """ values = read_attribute(shp_file,field_name) if field_name == 'INarea': # m^2 to km^2 values = [item/1000000.0 for item in values] fig_obj = plt.figure() # create a new figure ax = Subplot(fig_obj, 111) fig_obj.add_subplot(ax) # n, bins, patches = plt.hist(values, bins="auto", alpha=0.75,ec="black") # ec means edge color n, bins, patches = ax.hist(values, bins="auto", alpha=0.75, ec="black",linewidth='1.5',color=color,hatch=hatch) # print(n,bins,patches) # n_label = [str(i) for i in n] # plt.hist(values, bins="auto", alpha=0.75, ec="black",label=n_label) # plt.gcf().subplots_adjust(bottom=0.15) # reserve space for label # plt.xlabel(attribute,fontsize=15) # # plt.ylabel("Frequency") # plt.ylabel("Number",fontsize=15) # # plt.title('Histogram of '+attribute) # plt.text(60, .025, r'$\mu=100,\ \sigma=15$') # plt.axis([40, 160, 0, 0.03]) # hide the right and top boxed axis ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) # plt.grid(True) plt.savefig(output) basic.outputlogMessage("Output figures to %s"%os.path.abspath(output)) basic.outputlogMessage("ncount: " + str(n)) basic.outputlogMessage("bins: "+ str(bins))
def curvelinear_test1(fig): """ grid for custom transform. """ def tr(x, y): sgn = np.sign(x) x, y = np.abs(np.asarray(x)), np.asarray(y) return sgn * x**.5, y def inv_tr(x, y): sgn = np.sign(x) x, y = np.asarray(x), np.asarray(y) return sgn * x**2, y extreme_finder = angle_helper.ExtremeFinderCycle( 20, 20, lon_cycle=None, lat_cycle=None, # (0, np.inf), lon_minmax=None, lat_minmax=None, ) grid_helper = GridHelperCurveLinear((tr, inv_tr), extreme_finder=extreme_finder) ax1 = Subplot(fig, 111, 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) ax1.imshow(np.arange(25).reshape(5, 5), vmax=50, cmap=plt.cm.gray_r, interpolation="nearest", origin="lower") # tick density grid_helper.grid_finder.grid_locator1._nbins = 6 grid_helper.grid_finder.grid_locator2._nbins = 6
def curvelinear_test1(fig): """ grid for custom transform. """ def tr(x, y): sgn = np.sign(x) x, y = np.abs(np.asarray(x)), np.asarray(y) return sgn*x**.5, y def inv_tr(x, y): sgn = np.sign(x) x, y = np.asarray(x), np.asarray(y) return sgn*x**2, y extreme_finder = angle_helper.ExtremeFinderCycle(20, 20, lon_cycle=None, lat_cycle=None, # (0, np.inf), lon_minmax=None, lat_minmax=None, ) grid_helper = GridHelperCurveLinear((tr, inv_tr), extreme_finder=extreme_finder) ax1 = Subplot(fig, 111, 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) ax1.imshow(np.arange(25).reshape(5, 5), vmax=50, cmap=plt.cm.gray_r, interpolation="nearest", origin="lower") # tick density grid_helper.grid_finder.grid_locator1._nbins = 6 grid_helper.grid_finder.grid_locator2._nbins = 6
def draw_two_attribute_scatter(shp_file,field_name_1,field_name_2, output,color='grey',hatch=""): """ draw a scatter of two attributes Args: shp_file: shape file path field_name_1: x field_name_2: y output: save file path color: hatch: Returns:True if successful, False otherwise """ x_values = read_attribute(shp_file,field_name_1) y_values = read_attribute(shp_file,field_name_2) fig_obj = plt.figure() # create a new figure ax = Subplot(fig_obj, 111) fig_obj.add_subplot(ax) # n, bins, patches = plt.hist(values, bins="auto", alpha=0.75,ec="black") # ec means edge color # n, bins, patches = ax.hist(values, bins="auto", alpha=0.75, ec="black",linewidth='3',color=color,hatch=hatch) plt.scatter(x_values, y_values,marker='^',color=color) # print(n,bins,patches) # n_label = [str(i) for i in n] # plt.hist(values, bins="auto", alpha=0.75, ec="black",label=n_label) # plt.gcf().subplots_adjust(bottom=0.15) # reserve space for label # plt.xlabel(attribute,fontsize=15) # # plt.ylabel("Frequency") # plt.ylabel("Number",fontsize=15) # # # plt.title('Histogram of '+attribute) # # plt.text(60, .025, r'$\mu=100,\ \sigma=15$') # # plt.axis([40, 160, 0, 0.03]) # marked area values area_range = [1500] for area in area_range: ax.axvline(x=area,color='k',linewidth=0.8,linestyle='--') ax.text(area+100, 0.55, '%d $\mathrm{m^2}$'%area, rotation=90,fontsize=20) # hide the right and top boxed axis # ax.axis["right"].set_visible(False) # ax.axis["top"].set_visible(False) # plt.grid(True) plt.savefig(output) basic.outputlogMessage("Output figures to %s"%os.path.abspath(output)) # basic.outputlogMessage("ncount: " + str(n)) # basic.outputlogMessage("bins: "+ str(bins)) # plt.show() pass
def add_figs(self, identifier1, identifier2, identifier3): for id1 in identifier1: for id2 in identifier2: if id2 not in self._figs[id1].keys(): self._figs[id1].update({id2: {}}) self._axs[id1].update({id2: {}}) for id3 in identifier3: if id3 not in self._figs[id1][id2].keys(): self._figs[id1][id2].update({id3: plt.figure()}) self._axs[id1][id2].update( {id3: Subplot(self._figs[id1][id2][id3], 111)}) self._figs[id1][id2][id3].add_subplot( self._axs[id1][id2][id3])
def plottraces(atfobj): # plt.figure creates a matplotlib.figure.Figure instance fig = plt.figure() rect = fig.patch # a rectangle instance rect.set_alpha(0) # set the background of the figure to be transparent #use the weird Subplot imported from the toolkits to make your axes container? #then add this axes to to figure explicitly ax1 = Subplot(fig,111) ax1.patch.set_alpha(0) # set the background of the plotting axes to be transparent fig.add_subplot(ax1) # this weird Subplot imported from the toolkits let you indivdually set the axis lines to be invisible # now I am hiding all of the axis lines ax1.axis["right"].set_visible(False) ax1.axis["top"].set_visible(False) ax1.axis["bottom"].set_visible(False) ax1.axis["left"].set_visible(False) ax1.plot(atfobj.data[:,1],color = 'black') ax1.plot(atfobj.data[:,2]+0.06, color = 'blue') return fig
def plot_test(): # style fig = plt.figure() ax = Subplot(fig, 111) fig.add_subplot(ax) ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) # values plt.plot([1, 2, 3, 4]) # context plt.ylabel('some numbers') plt.show()
def draw_Flinn(self): self.plotFigure.clf() fontsize = self.settings.general_settings['fontsize'] self.plotaxes = axes = Subplot(self.plotFigure, 111, clip_on='True',\ xlim=(-0.2,7.2), ylim=(-0.2,7.2), autoscale_on='True',\ xlabel='ln(S2/S3)', ylabel='ln(S1/S2)', label='flinn',\ aspect='equal', adjustable='box',anchor='W') self.plotFigure.add_subplot(axes) self.plotaxes.format_coord = self.read_flinn axes.axis['right'].set_visible(False) axes.axis['top'].set_visible(False) for i in [0.2, 0.5, 1.0, 2.0, 5.0]: if i <= 1.0: diag = Line2D((0, 7.0), (0, (i * 7.0)), c='grey', lw=0.5) axes.add_line(diag) else: diag = Line2D((0, (7.0 / i)), (0, 7.0), c='grey', lw=0.5) axes.add_line(diag) for j in [2, 4, 6]: diag2 = Line2D((0, j), (j, 0), c='grey', lw=0.5) axes.add_line(diag2) axes.text(6.25,0.05,'K = 0',family='sans-serif',size=fontsize, \ horizontalalignment='left',color='grey') axes.text(0.15,6.1,'K = inf.',family='sans-serif',size=fontsize, \ horizontalalignment='left',color='grey',rotation='vertical') axes.text(6.45,6.4,'K = 1',family='sans-serif',size=fontsize, \ horizontalalignment='center',color='grey',rotation='45') axes.text(3.2,6.4,'K = 2',family='sans-serif',size=fontsize, \ horizontalalignment='center',color='grey',rotation='63.5') axes.text(1.2,6.4,'K = 5',family='sans-serif',size=fontsize, \ horizontalalignment='center',color='grey',rotation='78.7') axes.text(6.4,3.1,'K = 0.5',family='sans-serif',size=fontsize, \ horizontalalignment='center',color='grey',rotation='26.6') axes.text(6.5,1.3,'K = 0.2',family='sans-serif',size=fontsize, \ horizontalalignment='center',color='grey',rotation='11.3') axes.text(2.6,3.35,'C = 6',family='sans-serif',size=fontsize, \ horizontalalignment='center',color='grey',rotation='-45') axes.text(1.75,2.2,'C = 4',family='sans-serif',size=fontsize, \ horizontalalignment='center',color='grey',rotation='-45') axes.text(3.5,3.75,'Girdle/Cluster Transition',family='sans-serif',\ size=fontsize, horizontalalignment='left',\ verticalalignment='bottom',\ color='grey',rotation='45') axes.text(6.5,7.2,'CLUSTERS',family='sans-serif',size=fontsize, \ horizontalalignment='right',verticalalignment='bottom',\ color='grey') axes.text(7.2,6.5,'GIRDLES',family='sans-serif',size=fontsize, \ horizontalalignment='left',verticalalignment='top',\ color='grey',rotation='-90') for plot_item in self.plot_list: element, = axes.plot(plot_item.kx, plot_item.ky, linestyle='',\ **plot_item.point_settings) if plot_item.legend: self.legend_items.append((element, plot_item.legend_text)) axes.set_xlim(0.0, 7.2) axes.set_ylim(0.0, 7.2)
def draw_Flinn(self): self.plotFigure.clf() fontsize = self.settings.general_settings["fontsize"] self.plotaxes = axes = Subplot( self.plotFigure, 111, clip_on="True", xlim=(-0.2, 7.2), ylim=(-0.2, 7.2), autoscale_on="True", xlabel="ln(S2/S3)", ylabel="ln(S1/S2)", label="flinn", aspect="equal", adjustable="box", anchor="W", ) self.plotFigure.add_subplot(axes) self.plotaxes.format_coord = self.read_flinn axes.axis["right"].set_visible(False) axes.axis["top"].set_visible(False) for i in [0.2, 0.5, 1.0, 2.0, 5.0]: if i <= 1.0: diag = Line2D((0, 7.0), (0, (i * 7.0)), c="grey", lw=0.5) axes.add_line(diag) else: diag = Line2D((0, (7.0 / i)), (0, 7.0), c="grey", lw=0.5) axes.add_line(diag) for j in [2, 4, 6]: diag2 = Line2D((0, j), (j, 0), c="grey", lw=0.5) axes.add_line(diag2) axes.text( 6.25, 0.05, "K = 0", family="sans-serif", size=fontsize, horizontalalignment="left", color="grey", ) axes.text( 0.15, 6.1, "K = inf.", family="sans-serif", size=fontsize, horizontalalignment="left", color="grey", rotation="vertical", ) axes.text( 6.45, 6.4, "K = 1", family="sans-serif", size=fontsize, horizontalalignment="center", color="grey", rotation="45", ) axes.text( 3.2, 6.4, "K = 2", family="sans-serif", size=fontsize, horizontalalignment="center", color="grey", rotation="63.5", ) axes.text( 1.2, 6.4, "K = 5", family="sans-serif", size=fontsize, horizontalalignment="center", color="grey", rotation="78.7", ) axes.text( 6.4, 3.1, "K = 0.5", family="sans-serif", size=fontsize, horizontalalignment="center", color="grey", rotation="26.6", ) axes.text( 6.5, 1.3, "K = 0.2", family="sans-serif", size=fontsize, horizontalalignment="center", color="grey", rotation="11.3", ) axes.text( 2.6, 3.35, "C = 6", family="sans-serif", size=fontsize, horizontalalignment="center", color="grey", rotation="-45", ) axes.text( 1.75, 2.2, "C = 4", family="sans-serif", size=fontsize, horizontalalignment="center", color="grey", rotation="-45", ) axes.text( 3.5, 3.75, "Girdle/Cluster Transition", family="sans-serif", size=fontsize, horizontalalignment="left", verticalalignment="bottom", color="grey", rotation="45", ) axes.text( 6.5, 7.2, "CLUSTERS", family="sans-serif", size=fontsize, horizontalalignment="right", verticalalignment="bottom", color="grey", ) axes.text( 7.2, 6.5, "GIRDLES", family="sans-serif", size=fontsize, horizontalalignment="left", verticalalignment="top", color="grey", rotation="-90", ) for plot_item in self.plot_list: element, = axes.plot( plot_item.kx, plot_item.ky, linestyle="", **plot_item.point_settings ) if plot_item.legend: self.legend_items.append((element, plot_item.legend_text)) axes.set_xlim(0.0, 7.2) axes.set_ylim(0.0, 7.2)
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 PlotVollmer(self, event): #initialize the plot areas self.dataFigure.clf() axes = Subplot(self.dataFigure, 111, clip_on='True',xlim=(-0.1,1.05), ylim=(-0.1,1.05),autoscale_on='True',label='vollmer',aspect='equal', adjustable='box',anchor='SW') self.dataFigure.add_subplot(axes) axes.axis["right"].set_visible(False) axes.axis["top"].set_visible(False) axes.axis["bottom"].set_visible(False) axes.axis["left"].set_visible(False) try: sqrt3_2 = 0.866025 #m_sqrt(3)/2 tr1 = Line2D((0,1),(0,0),c='black') axes.add_line(tr1) tr2 = Line2D((0,0.5),(0,sqrt3_2),c='black') axes.add_line(tr2) tr3 = Line2D((1,0.5),(0,sqrt3_2),c='black') axes.add_line(tr3) for i in [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]: diag = Line2D((i/2,1.0-i/2),(sqrt3_2*i,sqrt3_2*i),c='grey',lw=0.5) axes.add_line(diag) diag2 = Line2D((i/2,i),(sqrt3_2*i,0),c='grey',lw=0.5) axes.add_line(diag2) diag3 = Line2D((i,i+(1-i)/2),(0,sqrt3_2-sqrt3_2*i),c='grey',lw=0.5) axes.add_line(diag3) axes.text(-0.08,-0.05,'Point',family='sans-serif',size=self.fontSize,horizontalalignment='left' ) axes.text(0.97,-0.05,'Girdle',family='sans-serif',size=self.fontSize,horizontalalignment='left' ) axes.text(0.5,0.88,'Random',family='sans-serif',size=self.fontSize,horizontalalignment='center' ) # label axes values for i in [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]: axes.text((1-i)/2, sqrt3_2*(1-i)-0.01, '%d' % (i*100), family='sans-serif', size=self.fontSize, horizontalalignment='right', color='grey', rotation='60') axes.text(i, -0.02,'%d' % (i*100), family='sans-serif', size=self.fontSize, horizontalalignment='center', verticalalignment='top', color='grey') axes.text(1.0-i/2, sqrt3_2*i-0.01,'%d' % (i*100) , family='sans-serif', size=self.fontSize, horizontalalignment='left', color='grey', rotation='-60') # ternary plot (from wikipedia) # P = (0,0) # G = (1,0) # R = (1/2, sqrt(3)/2) # given (P,G,R): # x = G + R/2 # y = (sqrt(3)/2) * R if len(self.idxPlan) == 0 and len(self.idxLin) == 0: # in case we have only one one opened file but it is not checked raise AttributeError else: for i in range(len(self.idxPlan)): x = self.PeigenList[i]["G"] + (self.PeigenList[i]["R"] / 2) y = self.PeigenList[i]["R"] * sqrt3_2 axes.plot(x,y, self.PProps[i]["PoleSymb"], c=self.PProps[i]["PolColor"], ms=self.PProps[i]["polespin"],label='%s n=%d' % (self.Pname[i],self.Pndata[i])) for j in range(len(self.idxLin)): x = self.LeigenList[j]["G"] + (self.LeigenList[j]["R"] / 2) y = self.LeigenList[j]["R"] * sqrt3_2 axes.plot(x,y, self.LProps[j]["LineSymb"], c=self.LProps[j]["LinColor"], ms=self.LProps[j]["linespin"],label='%s n=%d' % (self.Lname[j],self.Lndata[j])) axes.legend(bbox_to_anchor=(0.97, 0.8), loc=2, prop=FontProperties(size=self.fontSize),numpoints=1) axes.set_xlim(-0.1,1.05) axes.set_ylim(-0.1,1.05) self.dataCanvas.draw() except AttributeError: self.dataFigure.clf() dlg = wx.MessageDialog(None, _('No file(s) selected (checked).\n\n'), _('Oooops!'), wx.OK|wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() pass
def draw_Vollmer(self): self.plotFigure.clf() fontsize = self.settings.general_settings["fontsize"] self.plotaxes = axes = Subplot( self.plotFigure, 111, clip_on="True", xlim=(-0.1, 1.05), ylim=(-0.1, 1.05), autoscale_on="True", label="vollmer", aspect="equal", adjustable="box", anchor="SW", ) self.plotFigure.add_subplot(axes) self.plotaxes.format_coord = self.read_vollmer axes.axis["right"].set_visible(False) axes.axis["top"].set_visible(False) axes.axis["bottom"].set_visible(False) axes.axis["left"].set_visible(False) tr1 = Line2D((0, 1), (0, 0), c="black") axes.add_line(tr1) tr2 = Line2D((0, 0.5), (0, sqrt3_2), c="black") axes.add_line(tr2) tr3 = Line2D((1, 0.5), (0, sqrt3_2), c="black") axes.add_line(tr3) for i in [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]: diag = Line2D( (i / 2, 1.0 - i / 2), (sqrt3_2 * i, sqrt3_2 * i), c="grey", lw=0.5, ) axes.add_line(diag) diag2 = Line2D((i / 2, i), (sqrt3_2 * i, 0), c="grey", lw=0.5) axes.add_line(diag2) diag3 = Line2D( (i, i + (1 - i) / 2), (0, sqrt3_2 - sqrt3_2 * i), c="grey", lw=0.5, ) axes.add_line(diag3) axes.text( -0.08, -0.05, "Point", family="sans-serif", size=fontsize, horizontalalignment="left", ) axes.text( 0.97, -0.05, "Girdle", family="sans-serif", size=fontsize, horizontalalignment="left", ) axes.text( 0.5, 0.88, "Random", family="sans-serif", size=fontsize, horizontalalignment="center", ) for i in [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]: axes.text( (1 - i) / 2, sqrt3_2 * (1 - i) - 0.01, "%d" % (i * 100), family="sans-serif", size=fontsize, horizontalalignment="right", color="grey", rotation="60", ) axes.text( i, -0.02, "%d" % (i * 100), family="sans-serif", size=fontsize, horizontalalignment="center", verticalalignment="top", color="grey", ) axes.text( 1.0 - i / 2, sqrt3_2 * i - 0.01, "%d" % (i * 100), family="sans-serif", size=fontsize, horizontalalignment="left", color="grey", rotation="-60", ) for plot_item in self.plot_list: x = plot_item.G + (plot_item.R / 2.0) y = plot_item.R * sqrt3_2 element, = axes.plot( x, y, linestyle="", **plot_item.point_settings ) if plot_item.legend: self.legend_items.append((element, plot_item.legend_text)) axes.set_xlim(-0.1, 1.05) axes.set_ylim(-0.1, 1.05)
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 PlotFlinn(self, event): #initialize the plot areas self.dataFigure.clf() axes = Subplot(self.dataFigure, 111, clip_on='True',xlim=(-0.2,7.2), ylim=(-0.2,7.2),autoscale_on='True',xlabel='ln(S2/S3)',ylabel='ln(S1/S2)',label='flinn',aspect='equal', adjustable='box',anchor='W') self.dataFigure.add_subplot(axes) axes.axis["right"].set_visible(False) axes.axis["top"].set_visible(False) try: # plot lines of K for i in [0.2, 0.5, 1.0, 2.0, 5.0]: if i <= 1.0: diag = Line2D((0,7.0),(0,(i*7.0)),c='grey',lw=0.5) axes.add_line(diag) else: diag = Line2D((0,(7.0/i)),(0,7.0),c='grey',lw=0.5) axes.add_line(diag) # plot lines of C for j in [2,4,6]: diag2 = Line2D((0,j),(j,0),c='grey',lw=0.5) axes.add_line(diag2) # texts axes.text(6.25,0.05,'K = 0',family='sans-serif',size=self.fontSize,horizontalalignment='left',color='grey') axes.text(0.15,6.1,'K = inf.',family='sans-serif',size=self.fontSize,horizontalalignment='left',color='grey',rotation='vertical') axes.text(6.45,6.4,'K = 1',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='45') axes.text(3.2,6.4,'K = 2',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='63.5') axes.text(1.2,6.4,'K = 5',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='78.7') axes.text(6.4,3.1,'K = 0.5',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='26.6') axes.text(6.5,1.3,'K = 0.2',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='11.3') axes.text(2.6,3.35,'C = 6',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='-45') axes.text(1.75,2.2,'C = 4',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='-45') axes.text(3.5,3.75,'Girdle/Cluster Transition',family='sans-serif',size=self.fontSize,horizontalalignment='left',verticalalignment='bottom',color='grey',rotation='45') axes.text(6.5,7.2,'CLUSTERS',family='sans-serif',size=self.fontSize,horizontalalignment='right',verticalalignment='bottom',color='grey') axes.text(7.2,6.5,'GIRDLES',family='sans-serif',size=self.fontSize,horizontalalignment='left',verticalalignment='top',color='grey',rotation='-90') # plot the selected (checked) files # propsPList = [pdata, itemName, PolColor, symbPoles, polespin,... # propsLList = [pdata, itemName, LinColor, LineSymb, linespin,... if len(self.idxPlan) == 0 and len(self.idxLin) == 0: # in case we have only one one opened file but it is not checked raise AttributeError else: for i in range(len(self.idxPlan)): axes.plot(self.PeigenList[i]["K_x"],self.PeigenList[i]["K_y"], self.PProps[i]["PoleSymb"], c=self.PProps[i]["PolColor"], ms=self.PProps[i]["polespin"], label='%s n=%d' % (self.Pname[i],self.Pndata[i])) for j in range(len(self.idxLin)): axes.plot(self.LeigenList[j]["K_x"],self.LeigenList[j]["K_y"], self.LProps[j]["LineSymb"], c=self.LProps[j]["LinColor"], ms=self.LProps[j]["linespin"], label='%s n=%d' % (self.Lname[j],self.Lndata[j])) axes.legend(bbox_to_anchor=(1.1, 1), loc=2, prop=FontProperties(size='small'),numpoints=1) #set the axes limits and draws the stuff axes.set_xlim(0.0,7.2) axes.set_ylim(0.0,7.2) self.dataCanvas.draw() except AttributeError: self.dataFigure.clf() dlg = wx.MessageDialog(None, 'No file(s) selected (checked).\n\n', 'Oooops!', wx.OK|wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() pass
def scatter_plots(gmns=[], gms=[], matt=[], average=False, avmatt=False): ''' will plot to scatters of the RMSDs of GMnoscaled vs GMscaled and GMnoscaled vs MATT ''' if gms: r, pval = pearsonr(gmns, gms) line = r''' $r$=%.2f, pval=%.4f $R^2$=%.2f''' % (r, pval, r**2) fig = plt.figure() ax = Subplot(fig, 1, 1, 1) fig.add_subplot(ax) ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) ax.axis([min(gmns), max(gmns) + 0.5, min(gms), max(gms) + 0.5]) plt.plot(range(int(max(gmns)) + 3), 'r') plt.scatter(gmns, gms) ax.annotate(line, xy=(min(gmns) + 0.5, max(gms)), xytext=(min(gmns) + 0.5, max(gms))) if avmatt: plt.xlabel("Average Procrustes RMSD without scaling") plt.ylabel("Average Procrustes RMSD with scaling") plt.savefig('AvGMnsvsAvGMs.png') else: plt.xlabel("Procrustes RMSD without scaling") plt.ylabel("Procrustes RMSD with scaling") plt.savefig('GMnsvsGMs.png') #, transparent=True) r, pval = pearsonr(gmns, gms) line = r''' $r$=%.2f, pval=%.4f $R^2$=%.2f''' % (r, pval, r**2) fig2 = plt.figure() ax2 = Subplot(fig2, 1, 1, 1) fig2.add_subplot(ax2) ax2.axis["right"].set_visible(False) ax2.axis["top"].set_visible(False) ax2.axis([min(matt), max(matt) + 0.5, min(gmns), max(gmns) + 0.5]) plt.plot(range(int(max(gmns)) + 3), 'r') plt.scatter(matt, gmns) ax2.annotate(line, xy=(min(gmns) + 0.5, max(gms)), xytext=(min(gmns) + 0.5, max(gms))) if average: plt.xlabel("Number of Core residues") plt.ylabel( "Difference of average RMSD (mean(MATT) - mean(procrustes))") plt.savefig('diffvscore.png') elif avmatt: plt.xlabel("Average MATT RMSD") plt.ylabel("Average Procrustes RMSD without scaling") plt.savefig('AvMATTvsAvgmns.png') else: plt.xlabel("MATT alignment RMSD") plt.ylabel("Procrustes RMSD without scaling") plt.savefig('MattvsGMns.png') #, transparent=True)
## ax.axis[direction].set_visible(False) ## ax.set_xticks([]) ## ax.set_yticks([]) ## x = np.linspace(0, 2., 100) ## ax.plot(x, np.sin(x*np.pi)) ## #fig.savefig('different_axis.pdf') ## plt.show() import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.axes_grid.axislines import Subplot fig = plt.figure() ax = Subplot(fig, 111) fig.add_subplot(ax) ax.axis["right"].set_visible(False) ax.axis["left"].set_visible(False) ax.axis["top"].set_visible(False) ax.axis["bottom"].set_visible(False) x = np.linspace(0, 2., 100) ax.plot(x, np.sin(x*np.pi)) plt.tight_layout() fig.savefig('different_axis.pdf') #plt.show()
def write_legend2(data, upper, lower, figsize, mind, maxd, redblue, num_yrs, ylabel, xlabel, facecolor='0.8', linewidth=1., which_legend='subbasins'): """Write tiny legend to be plotted on map """ from matplotlib import pyplot as plt figleg = plt.figure(figsize=figsize) axleg = Subplot(figleg, 111) figleg.add_subplot(axleg) axleg.axis['top'].set_visible(False) axleg.axis['bottom'].set_visible(False) axleg.axis['right'].set_visible(False) yloc = plt.MaxNLocator(5) axleg.yaxis.set_major_locator(yloc) plt.ylim((mind, maxd)) plt.xlim(0, num_yrs) if redblue[0] == 'blue': cmap = ListedColormap(['r', 'b']) else: cmap = ListedColormap(['b', 'r']) norm = BoundaryNorm([-1e-3, 0, 1.e-3], cmap.N) # cmap.N is number of items in the colormap x, y = interp(range(num_yrs), data, 0., float(num_yrs - 1), 3 * num_yrs) plt.fill_between(range(num_yrs), upper, lower, facecolor='0.6', lw=0, alpha=1.) lc = colorline(x, y, z=y, cmap=cmap, norm=norm, linewidth=linewidth, maxd=maxd, mind=mind) plt.gca().add_collection(lc) font = {'size': '9'} mpl.rc('font', **font) plt.ylabel(ylabel, fontsize=6) axleg.text(-30., mind * 1.5, xlabel, fontsize=6, verticalalignment='top') if which_legend == 'subbasins': plt.savefig('tinyfig' + '12' + '.png', format="png", dpi=300, bbox_inches='tight', transparent=True) elif which_legend == 'EFs': plt.savefig('tinyfig' + '8' + '.png', format="png", dpi=300, bbox_inches='tight', transparent=True) plt.close() mpl.rcdefaults() return
dates = [] emails = [] reader = csv.reader(open('dasovich-dates.csv', 'r')) reader.next() # skip header for row in reader: dates.append(datetime.strptime(row[0], '%Y-%m')) # dates.append(row[0]) emails.append(float(row[1])) # PLOT fig = plt.figure() ax = Subplot(fig, 111) fig.add_subplot(ax) ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) plt.plot_date(dates, emails, xdate=True, ydate=False, linestyle='-', color='#333333') ax.grid(which='major', color='#999999') plt.xticks(rotation='vertical') plt.title('Monthly Email History for Jeff Dasovich') plt.ylabel('Number of Emails') plt.savefig('foo.pdf', transparent=True)
#!/usr/bin/env python import matplotlib.pyplot as plt from mpl_toolkits.axes_grid.axislines import Subplot fig1 = plt.figure(1, (3, 3), facecolor='white') ax1 = Subplot(fig1, 111) fig1.add_subplot(ax1) ax1.axis["right"].set_visible(False) ax1.axis["top"].set_visible(False) plt.show()
def plot_df_f0s(): fig = plt.figure(1, (3, 3)) ax = Subplot(fig, 111) fig.add_subplot(ax) ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) x = np.linspace(-333.3, 1498.5, num=55) # x = range(1, 56) for true_means, list_sems in zip(all_true_means, all_list_sems): ax.errorbar(x, true_means, yerr=list_sems, elinewidth=3, linewidth=4) ax.axvspan(0, 400, color="y", alpha=0.5, lw=0) ax.set_xticks([-200, 0, 200, 400, 600, 800, 1000, 1200, 1400]) ax.set_xlabel("Time (ms)") ax.set_ylabel(r"$\Delta F/F_0$(%)") ax.xaxis.set_tick_params(width=2, length=7) ax.yaxis.set_tick_params(width=2, length=7) # x_axis = np.linspace(3.333, 26.6667, num=800) # for df_df0 in list_df_f0: # plt.plot(df_df0) ax.set_ylim([-1.5, 2.5]) ax.set_xlim([-340, 1500]) # axes color.... jeff didn't like it :( # plt.axhline(linewidth=3, color='k') # plt.axvline(linewidth=3, color='k') # plt.xlim([3.333,26.6667]) # plt.plot([83, 83], [-0.015, 0.025], 'k-', lw=2) # plt.plot([203, 203], [-0.015, 0.025], 'k-', lw=2) # plt.plot([505, 505], [-0.015, 0.025], 'k-', lw=2) # plt.axvspan(5, 17, color='y', alpha=0.5, lw=0) # plt.axvspan(505, 517, color='y', alpha=0.5, lw=0) # for i in range(1, len(timings)): # plt.plot([timings[i], timings[i]], [-0.015, 0.025], 'k-', lw=2) plt.show()
import matplotlib.pyplot as plt from mpl_toolkits.axes_grid.axislines import Subplot fig = plt.figure(1, (3, 3)) ax = Subplot(fig, 111) fig.add_subplot(ax) ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) plt.show()
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) # 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) 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)
import matplotlib import matplotlib.pyplot as plt from mpl_toolkits.axes_grid.axislines import Subplot # name the output file pdfname = 'python_plot.pdf' # read input file: first column (X values) # second column (Y values) x, y, size = np.loadtxt('bubble.dat', unpack=True) size = size * 250. # create plot fig = plt.figure(1, (8,5), facecolor='white') ax = Subplot(fig, 111) fig.add_subplot(ax) # make axes invisible ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) ax.scatter(x, y, c='b', s=size, alpha=1.0, lw = 0) pl.ylabel('peak time rank number') pl.xlabel(r'log($\nu$) [ghz]') pl.ylim([0.0, 8.0]) pl.xlim([0.0, 2.5]) pl.savefig(pdfname)