本文整理汇总了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()
示例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
示例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()
示例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)
示例5: plotMatrix
def plotMatrix(cm):
pl.matshow(cm)
pl.title('Confusion matrix')
pl.colorbar()
pl.ylabel('True label')
pl.xlabel('Predicted label')
pl.show()
示例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);
示例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()
示例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()
示例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()
示例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
示例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()
示例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()
示例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)
示例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()
示例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()