我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用matplotlib.pylab.axes()。
def set_nice_params(): fsize=18 params = {'axes.labelsize': fsize, # 'font.family': 'serif', 'font.family': 'Times New Roman', 'figure.facecolor': 'white', 'text.fontsize': fsize, 'legend.fontsize': fsize, 'xtick.labelsize': fsize*0.8, 'ytick.labelsize': fsize*0.8, 'ytick.minor.pad': 8, 'ytick.major.pad': 8, 'xtick.minor.pad': 8, 'xtick.major.pad': 8, 'text.usetex': False, 'lines.markeredgewidth': 0} pl.rcParams.update(params)
def save_images(self, X, imgfile, density=False): ax = plt.axes() x = X[:, 0] y = X[:, 1] if density: xy = np.vstack([x,y]) z = scipy.stats.gaussian_kde(xy)(xy) ax.scatter(x, y, c=z, marker='o', edgecolor='') else: ax.scatter(x, y, marker='o', c=range(x.shape[0]), cmap=plt.cm.coolwarm) if self.collection is not None: self.collection.set_transform(ax.transData) ax.add_collection(self.collection) ax.text(x[0], y[0], str('start'), transform=ax.transAxes) ax.axis([-0.2, 1.2, -0.2, 1.2]) fig = plt.gcf() plt.savefig(imgfile) plt.close()
def plot_confusion_matrix(cm, label_list, title='Confusion matrix', cmap=None): from matplotlib import pylab cm = np.asarray(cm, dtype=np.float32) for i, row in enumerate(cm): cm[i] = cm[i] / np.sum(cm[i]) #import matplotlib.pyplot as plt #plt.ion() pylab.clf() pylab.matshow(cm, fignum=False, cmap='Blues', vmin=0, vmax=1.0) ax = pylab.axes() ax.set_xticks(range(len(label_list))) ax.set_xticklabels(label_list, rotation='vertical') ax.xaxis.set_ticks_position('bottom') ax.set_yticks(range(len(label_list))) ax.set_yticklabels(label_list) pylab.title(title) pylab.colorbar() pylab.grid(False) pylab.xlabel('Predicted class') pylab.ylabel('True class') pylab.grid(False) pylab.savefig('test.jpg') pylab.show()
def plot_confusion_matrix(cm, genre_list, name, title): pylab.clf() pylab.matshow(cm, fignum=False, cmap='Blues', vmin=0, vmax=1.0) ax = pylab.axes() ax.set_xticks(range(len(genre_list))) ax.set_xticklabels(genre_list) ax.xaxis.set_ticks_position("bottom") ax.set_yticks(range(len(genre_list))) ax.set_yticklabels(genre_list) pylab.title(title) pylab.colorbar() pylab.grid(False) pylab.show() pylab.xlabel('Predicted class') pylab.ylabel('True class') pylab.grid(False) pylab.savefig( os.path.join(CHART_DIR, "confusion_matrix_%s.png" % name), bbox_inches="tight")
def plot_confusion_matrix(cm, plot_title, filename, genres=None): if not genres: genres = GENRES pylab.clf() pylab.matshow(cm, fignum=False, cmap='Blues', vmin=0, vmax=100.0) axes = pylab.axes() axes.set_xticks(range(len(genres))) axes.set_xticklabels(genres, rotation=45) axes.set_yticks(range(len(genres))) axes.set_yticklabels(genres) axes.xaxis.set_ticks_position("bottom") pylab.title(plot_title, fontsize=14) pylab.colorbar() pylab.xlabel('Predicted class', fontsize=12) pylab.ylabel('Correct class', fontsize=12) pylab.grid(False) #pylab.show() pylab.savefig(os.path.join(PLOTS_DIR, "cm_%s.eps" % filename), bbox_inches="tight")
def image(Z,xnew,ynew,my_cmap=None,aspect='equal'): """ Creates pretty image. You need to specify: """ imshow(log10(Z),extent=[xnew[0],xnew[-1],ynew[0],ynew[-1]], cmap=my_cmap) pylab.axes().set_aspect('equal') colorbar() circle2=Circle((0,0),1,color='k') gca().add_artist(circle2) savefig('tmp.png',transparent=True,dpi=150)