当前位置: 首页>>代码示例>>Python>>正文


Python pylab.matshow函数代码示例

本文整理汇总了Python中pylab.matshow函数的典型用法代码示例。如果您正苦于以下问题:Python matshow函数的具体用法?Python matshow怎么用?Python matshow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了matshow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: showDistMatrix

def showDistMatrix(distMatrix):		
	pylab.matshow(distMatrix)
 	ax = pylab.gca() 
 	bottom, top = ax.get_ylim()
	ax.set_ylim(top, bottom)		
	pylab.colorbar() 
	pylab.show()
开发者ID:stefanSchinkel,项目名称:crpy,代码行数:7,代码来源:plots.py

示例2: kappa_residual_grid_plot

def kappa_residual_grid_plot(env, model, base_model, obj_index, with_contours=False, only_contours=False, with_colorbar=True):
    obj0,data0 = base_model['obj,data'][obj_index]
    obj1,data1 = model['obj,data'][obj_index]

    kappa = data1['kappa'] - data0['kappa']
       
    grid = obj1.basis._to_grid(kappa, obj1.basis.subdivision)
    R = obj1.basis.mapextent

    kw = {'extent': [-R,R,-R,R],
          'interpolation': 'nearest',
          'aspect': 'equal',
          'origin': 'upper',
          'cmap': cm.gist_stern,
          'fignum': False}
          #'vmin': -1,
          #'vmax':  1}

    if not only_contours:
        pl.matshow(grid, **kw)
    if only_contours or with_contours:
        kw.update({'colors':'k', 'linewidths':1, 'cmap':None})
        pl.contour(grid, **kw)
        kw.update({'colors':'k', 'linewidths':2, 'cmap':None})
        pl.contour(grid, [0], **kw)

    if with_colorbar:
        glscolorbar()
    return
开发者ID:RafiKueng,项目名称:glass,代码行数:29,代码来源:plots.py

示例3: benchmark

def benchmark(clf_class, params, name):
    print("parameters:", params)
    t0 = time()
    clf = clf_class(**params).fit(X_train, y_train)
    print("done in %fs" % (time() - t0))

    if hasattr(clf, 'coef_'):
        print("Percentage of non zeros coef: %f"
              % (np.mean(clf.coef_ != 0) * 100))
    print("Predicting the outcomes of the testing set")
    t0 = time()
    pred = clf.predict(X_test)
    print("done in %fs" % (time() - t0))

    print("Classification report on test set for classifier:")
    print(clf)
    print()
    print(classification_report(y_test, pred,
                                target_names=news_test.target_names))

    cm = confusion_matrix(y_test, pred)
    print("Confusion matrix:")
    print(cm)

    # Show confusion matrix
    pl.matshow(cm)
    pl.title('Confusion matrix of the %s classifier' % name)
    pl.colorbar()
开发者ID:Big-Data,项目名称:scikit-learn,代码行数:28,代码来源:mlcomp_sparse_document_classification.py

示例4: train_model

def train_model(trainset):
	word_vector = TfidfVectorizer(analyzer="word", ngram_range=(2,2), binary = False, max_features= 2000,min_df=1,decode_error="ignore")
#	print word_vector	
	print "works fine"
	char_vector = TfidfVectorizer(ngram_range=(2,3), analyzer="char", binary = False, min_df = 1, max_features = 2000,decode_error= "ignore")
	vectorizer =FeatureUnion([ ("chars", char_vector),("words", word_vector) ])
	corpus = []
	classes = []

	for item in trainset:
		corpus.append(item['text'])
		classes.append(item['label'])

	print "Training instances : ", 0.8*len(classes)
	print "Testing instances : ", 0.2*len(classes) 
	
	matrix = vectorizer.fit_transform(corpus)
	print "feature count : ", len(vectorizer.get_feature_names())
	print "training model"
	X = matrix.toarray()
	y = numpy.asarray(classes)
	model =LinearSVC()
	X_train, X_test, y_train, y_test= train_test_split(X,y,train_size=0.8,test_size=.2,random_state=0)
	y_pred = OneVsRestClassifier(model).fit(X_train, y_train).predict(X_test)
	#y_prob = OneVsRestClassifier(model).fit(X_train, y_train).decision_function(X_test)
	#print y_prob
	#con_matrix = []
	#for row in range(len(y_prob)):
	#	temp = [y_pred[row]]	
	#	for prob in y_prob[row]:
	#		temp.append(prob)
	#	con_matrix.append(temp)
	#for row in con_matrix:
	#	output.write(str(row)+"\n")
	#print y_pred		
	#print y_test
	
	res1=[i for i, j in enumerate(y_pred) if j == 'anonEdited']
	res2=[i for i, j in enumerate(y_test) if j == 'anonEdited']
	reset=[]
	for r in res1:
		if y_test[r] != "anonEdited":
			reset.append(y_test[r])
	for r in res2:
		if y_pred[r] != "anonEdited":
			reset.append(y_pred[r])
	
	
	output=open(sys.argv[2],"w")
	for suspect in reset:
		output.write(str(suspect)+"\n")	
	cm = confusion_matrix(y_test, y_pred)
	print(cm)
	pl.matshow(cm)
	pl.title('Confusion matrix')
	pl.colorbar()
	pl.ylabel('True label')
	pl.xlabel('Predicted label')
	pl.show()
	print accuracy_score(y_pred,y_test)
开发者ID:srini21,项目名称:Amazon-deceptive-reviews,代码行数:60,代码来源:anontesting.py

示例5: plotMatrix

def plotMatrix(cm):
    pl.matshow(cm)
    pl.title('Confusion matrix')
    pl.colorbar()
    pl.ylabel('True label')
    pl.xlabel('Predicted label')
    pl.show()
开发者ID:AkiraKane,项目名称:Python,代码行数:7,代码来源:confusion_matrix.py

示例6: transect

def transect(x,y,z,x0,y0,x1,y1,plots=0):
    #convert coord to pixel coord
    d0=sqrt( (x-x0)**2+ (y-y0)**2 );
    i0=d0.argmin();
    x0,y0=unravel_index(i0,x.shape); #overwrite x0,y0
    
    d1=plt.np.sqrt( (x-x1)**2+ (y-y1)**2 );
    i1=d1.argmin();
    x1,y1=unravel_index(i1,x.shape); #overwrite x1,y1    
    #-- Extract the line...    
    # Make a line with "num" points...
    length = int(plt.np.hypot(x1-x0, y1-y0))
    xi, yi = plt.np.linspace(x0, x1, length), plt.np.linspace(y0, y1, length) 
       
    # Extract the values along the line
    #y is the first dimension and x is the second, row,col
    zi = z[xi.astype(plt.np.int), yi.astype(plt.np.int)]
    mz=nonaninf(z.ravel()).mean()
    sz=nonaninf(z.ravel()).std()
    if plots==1:
        plt.matshow(z);plt.clim([mz-2*sz,mz+2*sz]);plt.colorbar();plt.title('transect: (' + str(x0) + ',' + str(y0) + ') (' +str(x1) + ',' +str(y1) + ')' );
        plt.scatter(yi,xi,5,c='r',edgecolors='none')
        plt.figure();plt.scatter(sqrt( (xi-xi[0])**2 + (yi-yi[0])**2 ) , zi)
        #plt.figure();plt.scatter(xi, zi)
        #plt.figure();plt.scatter(yi, zi)

    return (xi, yi, zi);
开发者ID:Terradue,项目名称:adore-doris,代码行数:27,代码来源:__init__.py

示例7: main

def main():
    import pylab
    
    # Create the gaussian data
    Xin, Yin = pylab.mgrid[0:201, 0:201]
    data = gaussian(3, 100, 100, 20, 40)(Xin, Yin) + np.random.random(Xin.shape)
    
    pylab.matshow(data, cmap='gist_rainbow')
    
    params = fitgaussian(data)
    fit = gaussian(*params)
    
    pylab.contour(fit(*pylab.indices(data.shape)), cmap='copper')
    ax = pylab.gca()
    (height, x, y, width_x, width_y) = params
    
    pylab.text(0.95, 0.05, """
    x : %.1f
    y : %.1f
    width_x : %.1f
    width_y : %.1f""" %(x, y, width_x, width_y),
            fontsize=16, horizontalalignment='right',
            verticalalignment='bottom', transform=ax.transAxes)
    
    pylab.show()
开发者ID:seddon-software,项目名称:python3-examples,代码行数:25,代码来源:_02_fit_gaussian.py

示例8: HarmonicResponseViewer

def HarmonicResponseViewer(bw,harmonicResponse,title="",mode="COS_SIN"):
    #
    # okay I should make the matrix full of zeros and then set the values
    # as I go through the harmonicResponse

    #First we do regular bar charts plot

    #pprint(harmonicResponse)
    data=[[a,b,c,d] for (a,b),(c,d) in harmonicResponse]
    for mval in range(bw+1):
        HarmonicBarChart(mval,data,mchoiceMinusOne=False)
        HarmonicBarChart(mval,data,showPrime=True,mchoiceMinusOne=False)
    #Then the matrix plots

    
    mat_cos=zeros((bw,bw))
    mat_sin=mat_cos
    for (x,y),(c,s) in harmonicResponse:
        mat_cos[y][x]=c
        mat_sin[y][x]=s

    pylab.matshow(mat_cos)
    pylab.title(title+" cos")
    pylab.xlabel("n")
    pylab.ylabel("m")
    pylab.show()
    pylab.matshow(mat_sin)
    pylab.title(title+" sin")
    pylab.xlabel("n")
    pylab.ylabel("m")
    pylab.show()
开发者ID:cjwiggins,项目名称:MagnetoShim,代码行数:31,代码来源:FieldViewUtils.py

示例9: matrix_picture

def matrix_picture(matrix):
    pl.matshow(matrix)
    pl.title('Confusion matrix')
    pl.colorbar()
    pl.ylabel('True label')
    pl.xlabel('Predicted label')
    pl.show()
开发者ID:frabsovk,项目名称:data_mining_2014,代码行数:7,代码来源:zapoctova_prace.py

示例10: show_chains

def show_chains(rbm, state, dataset, num_particles=20, num_samples=20, show_every=10, display=True,
                figname='Gibbs chains', figtitle='Gibbs chains'):
    samples = gnp.zeros((num_particles, num_samples, state.v.shape[1]))
    state = state[:num_particles, :, :]

    for i in range(num_samples):
        samples[:, i, :] = rbm.vis_expectations(state.h)
        
        for j in range(show_every):
            state = rbm.step(state)

    npix = dataset.num_rows * dataset.num_cols
    rows = [vm.hjoin([samples[i, j, :npix].reshape((dataset.num_rows, dataset.num_cols)).as_numpy_array()
                      for j in range(num_samples)],
                     normalize=False)
            for i in range(num_particles)]
    grid = vm.vjoin(rows, normalize=False)

    if display:
        pylab.figure(figname)
        pylab.matshow(grid, cmap='gray', fignum=False)
        pylab.title(figtitle)
        pylab.gcf().canvas.draw()

    return grid
开发者ID:rgrosse,项目名称:fang,代码行数:25,代码来源:diagnostics.py

示例11: gradient_grid_plot

def gradient_grid_plot(env, model, obj_index):
    obj,data = model['obj,data'][obj_index]
    b = obj.basis
    kappa = data['kappa']
    grid = np.zeros_like(kappa)

    #wght = lambda x: 1.0 / len(x) if len(x) else 0
    wght = lambda x: b.cell_size[x]**2 / np.sum(b.cell_size[x]**2)
    for i,r in enumerate(b.ploc):
        n,e,s,w = b.nbrs3[i][2]

        dx = np.sum(kappa[w] * wght(w)) - np.sum(kappa[e] *  wght(e))
        dy = np.sum(kappa[s] * wght(s)) - np.sum(kappa[n] *  wght(n))

        dx*=-1
        dy*=-1

        #print dx, dy

        dr = np.sqrt(dx**2 + dy**2)
        grid[i] = dr 

    grid = grid
    kw = default_kw(b.mapextent, vmin=np.amin(grid), vmax=np.amax(grid))
    grid = b._to_grid(grid, b.subdivision)
    pl.matshow(grid, **kw)
    glscolorbar()
开发者ID:RafiKueng,项目名称:glass,代码行数:27,代码来源:plots.py

示例12: displayResult

def displayResult(keypoints, currentImage):
	pl.ion()
	pl.gray()
	pl.matshow(currentImage)
	for feature in keypoints:
		print feature
		pl.plot(feature[0], feature[1], 'bo')
	pl.show()
开发者ID:enjooblena,项目名称:cs180mp,代码行数:8,代码来源:cs180functions.py

示例13: visualize_row

def visualize_row(g, nvis=196, nhid=20, title=''):
    ncols = np.sqrt(nvis).astype(int)

    title = 'vishid'
    vishid = g[nvis+nhid:].reshape((nvis, nhid))
    imgs = [vishid[:, j].reshape((ncols, ncols)) for j in range(nhid)]
    pylab.matshow(vm.pack(imgs), cmap='gray')
    pylab.title(title)
开发者ID:rgrosse,项目名称:fang,代码行数:8,代码来源:fisher_vis.py

示例14: show_gfx

def show_gfx(world):
    if VISUAL:
        top=world.max()
        if top>50.0: cscheme=hot
        elif top>0.0: cscheme=temp
        else: cscheme=cold
        pylab.matshow(world, fignum=1, cmap=cscheme)
        pylab.draw()
开发者ID:Freaken,项目名称:DatVid,代码行数:8,代码来源:climate-new.py

示例15: plot_dist_matrix

def plot_dist_matrix(name, mec):
    mec.execute('_dm = %s.get_dist_matrix()' % name, 0)
    _dm = mec.zip_pull('_dm', 0)
    import pylab
    pylab.ion()
    pylab.matshow(_dm)
    pylab.colorbar()
    pylab.show()
开发者ID:MJones810,项目名称:distarray,代码行数:8,代码来源:proxy.py


注:本文中的pylab.matshow函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。