我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用pylab.axes()。
def add_colorbar(ax, im, side='right', size='5%', pad=0.1, **kwds): """ Add colorbar to the axes *ax* with colors corresponding to the color mappable object *im*. Place the colorbar at the *side* of *ax* (options are `'right'`, `'left'`, `'top'`, or `'bottom'`). The width (or height) of the colorbar is specified by *size* and is relative to *ax*. Add space *pad* between *ax* and the colorbar. The remaining keyword arguments *kwds* are passed to the call to :func:`colorbar`. Return the colorbar instance. Reference: http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html """ divider = make_axes_locatable(ax) cax = divider.append_axes(side, size=size, pad=pad) cb = PL.colorbar(im, cax=cax, **kwds) PL.axes(ax) return cb
def mybut(text, dummy, xl, yb, xw=0, yh=0, axisbg=None, color=0.85, fun=None, bspace=0.005): """ create axes and populate button with text, automatically adjusting xw if not given. Has a side effect on xl. (button_layout_cursor) dummy is for if and when I can place these on an obect rather than using pylab """ if axisbg==None: axisbg='lightgoldenrodyellow' global button_layout_cursor if xw==0: xw=0.015*(len(text)+1) if yh==0: yh=0.05 ## thisax=fig.add_axes([xl, yb, xw, yh], axisbg=axisbg) fundamentally wrong thisax=pl.axes([xl, yb, xw, yh], axisbg=axisbg) thisbut=Button(thisax, text) thisbut.on_clicked(fun) button_layout_cursor += xw+bspace return(thisbut)
def generateImages(picklefile, pickledir, filehash, imagedir, pietype): leaf_file = open(os.path.join(pickledir, picklefile), 'rb') (piedata, pielabels) = cPickle.load(leaf_file) leaf_file.close() pylab.figure(1, figsize=(6.5,6.5)) ax = pylab.axes([0.2, 0.15, 0.6, 0.6]) pylab.pie(piedata, labels=pielabels) pylab.savefig(os.path.join(imagedir, '%s-%s.png' % (filehash, pietype))) pylab.gcf().clear() os.unlink(os.path.join(pickledir, picklefile))
def class_distributions(): # Create the Class Distributions Diagram labels = ['Diamond', 'Platinum', 'Gold', 'Silver', 'Bronze'] fracs = [1.89, 8.05, 23.51, 38.96, 27.59] figure(1, figsize=(6,6)) ax = axes([0.1, 0.1, 0.8, 0.8]) pie(fracs, labels=labels, autopct='%1.1f%%') title('Tier Population Distribution', bbox={'facecolor': '0.8', 'pad': 5}) savefig('images/pie.png')
def plot_map(ax=None, alpha=0.3, zorder=0): """ Add map features (coastlines, national boundaries, etc.) to *a* with transparency level *alpha* and *zorder*. Return *ax*. """ if ax is None: ax = PL.axes(projection=ccrs.PlateCarree()) # national boundaries boundaries_50m = cartopy.feature.NaturalEarthFeature(category='cultural', name='admin_0_boundary_lines_land', scale='50m', edgecolor='k', facecolor='none') ax.add_feature(boundaries_50m, alpha=alpha, zorder=zorder) # states states_50m = cartopy.feature.NaturalEarthFeature(category='cultural', name='admin_1_states_provinces_lines', scale='50m', edgecolor='k', facecolor='none') ax.add_feature(states_50m, alpha=alpha, zorder=zorder) # coastlines coastline_50m = cartopy.feature.NaturalEarthFeature('physical', 'coastline', '50m', edgecolor='k', facecolor='none') ax.add_feature(coastline_50m, alpha=alpha, zorder=zorder) # lakes lakes_110m = cartopy.feature.NaturalEarthFeature('physical', 'lakes', '110m', edgecolor='k', facecolor='none') # add all shape objects ax.add_feature(lakes_110m, alpha=alpha, zorder=zorder) return ax
def plotPrecisionRecallDiagram(title="title", points=None, labels=None, loc="best",xy_ranges = [0.6, 1.0, 0.6, 1.0], save_file = None): """Plot (precision,recall) values with 10 f-Measure equipotential lines. Plots into the current canvas. Points is a list of (precision,recall) pairs. Optionally you can also provide labels (list of strings), which will be used to create a legend, which is located at loc. """ if labels: ax = pl.axes([0.1, 0.1, 0.7, 0.8]) # llc_x, llc_y, width, height else: ax = pl.gca() pl.title(title) pl.xlabel("Precision") pl.ylabel("Recall") _plotFMeasures(start = min(xy_ranges[0],xy_ranges[2]), end = max(xy_ranges[1],xy_ranges[3])) if points: getColor = it.cycle(colors).next getMarker = it.cycle(markers).next scps = [] # scatter points for i, (x, y) in enumerate(points): label = None if labels: label = labels[i] print i, x, y, label scp = ax.scatter(x, y, label=label, s=50, linewidths=0.75, facecolor=getColor(), alpha=0.75, marker=getMarker()) scps.append(scp) # pl.plot(x,y, label=label, marker=getMarker(), markeredgewidth=0.75, markerfacecolor=getColor()) # if labels: pl.text(x, y, label, fontsize="x-small") if labels: # pl.legend(scps, labels, loc=loc, scatterpoints=1, numpoints=1, fancybox=True) # passing scps & labels explicitly to work around a bug with legend seeming to miss out the 2nd scatterplot #pl.legend(scps, labels, loc=(1.01, 0), scatterpoints=1, numpoints=1, fancybox=True) # passing scps & labels explicitly to work around a bug with legend seeming to miss out the 2nd scatterplot pl.legend(scps, labels, loc= loc, scatterpoints=1, numpoints=1, fancybox=True,fontsize = 10) # passing scps & labels explicitly to work around a bug with legend seeming to miss out the 2nd scatterplot pl.axis(xy_ranges) # xmin, xmax, ymin, ymax if save_file: pl.savefig(save_file) pl.show() pl.close()