本文整理汇总了Python中pylab.colorbar方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.colorbar方法的具体用法?Python pylab.colorbar怎么用?Python pylab.colorbar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylab
的用法示例。
在下文中一共展示了pylab.colorbar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_wt_layout
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def plot_wt_layout(wt_layout, borders=None, depth=None):
fig = plt.figure(figsize=(6,6), dpi=2000)
fs = 14
ax = plt.subplot(111)
if depth is not None:
N = 100
X, Y = plt.meshgrid(plt.linspace(depth[:,0].min(), depth[:,0].max(), N),
plt.linspace(depth[:,1].min(), depth[:,1].max(), N))
Z = plt.griddata(depth[:,0],depth[:,1],depth[:,2],X,Y, interp='linear')
plt.contourf(X,Y,Z, label='depth [m]')
plt.colorbar().set_label('water depth [m]')
#ax.plot(wt_layout.wt_positions[:,0], wt_layout.wt_positions[:,1], 'or', label='baseline position')
ax.scatter(wt_layout.wt_positions[:,0], wt_layout.wt_positions[:,1], wt_layout._wt_list('rotor_diameter'), label='baseline position')
if borders is not None:
ax.plot(borders[:,0], borders[:,1], 'r--', label='border')
ax.set_xlabel('x [m]');
ax.set_ylabel('y [m]')
ax.axis('equal');
ax.legend(loc='lower left')
示例2: heatmap
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def heatmap(df,fname=None,cmap='seismic',log=False):
"""Plot a heat map"""
from matplotlib.colors import LogNorm
f=plt.figure(figsize=(8,8))
ax=f.add_subplot(111)
norm=None
df=df.replace(0,.1)
if log==True:
norm=LogNorm(vmin=df.min().min(), vmax=df.max().max())
hm = ax.pcolor(df,cmap=cmap,norm=norm)
plt.colorbar(hm,ax=ax,shrink=0.6,norm=norm)
plt.yticks(np.arange(0.5, len(df.index), 1), df.index)
plt.xticks(np.arange(0.5, len(df.columns), 1), df.columns, rotation=90)
#ax.axvline(4, color='gray'); ax.axvline(8, color='gray')
plt.tight_layout()
if fname != None:
f.savefig(fname+'.png')
return ax
示例3: plot_confusion_matrix
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def plot_confusion_matrix(self, matrix, labels):
if not self.to_save and not self.to_show:
return
pylab.figure()
pylab.imshow(matrix, interpolation='nearest', cmap=pylab.cm.jet)
pylab.title("Confusion Matrix")
for i, vi in enumerate(matrix):
for j, vj in enumerate(vi):
pylab.annotate("%.1f" % vj, xy=(j, i), horizontalalignment='center', verticalalignment='center', fontsize=9)
pylab.colorbar()
classes = np.arange(len(labels))
pylab.xticks(classes, labels)
pylab.yticks(classes, labels)
pylab.ylabel('Expected label')
pylab.xlabel('Predicted label')
示例4: plot_functional_map
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def plot_functional_map(C, newfig=True):
vmax = max(np.abs(C.max()), np.abs(C.min()))
vmin = -vmax
C = ((C - vmin) / (vmax - vmin)) * 2 - 1
if newfig:
pl.figure(figsize=(5,5))
else:
pl.clf()
ax = pl.gca()
pl.pcolor(C[::-1], edgecolor=(0.9, 0.9, 0.9, 1), lw=0.5,
vmin=-1, vmax=1, cmap=nice_mpl_color_map())
# colorbar
tick_locs = [-1., 0.0, 1.0]
tick_labels = ['min', 0, 'max']
bar = pl.colorbar()
bar.locator = matplotlib.ticker.FixedLocator(tick_locs)
bar.formatter = matplotlib.ticker.FixedFormatter(tick_labels)
bar.update_ticks()
ax.set_aspect(1)
pl.xticks([])
pl.yticks([])
if newfig:
pl.show()
示例5: plotFields
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def plotFields(layer,fieldShape=None,channel=None,figOffset=1,cmap=None,padding=0.01):
# Receptive Fields Summary
try:
W = layer.W
except:
W = layer
wp = W.eval().transpose();
if len(np.shape(wp)) < 4: # Fully connected layer, has no shape
fields = np.reshape(wp,list(wp.shape[0:-1])+fieldShape)
else: # Convolutional layer already has shape
features, channels, iy, ix = np.shape(wp)
if channel is not None:
fields = wp[:,channel,:,:]
else:
fields = np.reshape(wp,[features*channels,iy,ix])
perRow = int(math.floor(math.sqrt(fields.shape[0])))
perColumn = int(math.ceil(fields.shape[0]/float(perRow)))
fig = mpl.figure(figOffset); mpl.clf()
# Using image grid
from mpl_toolkits.axes_grid1 import ImageGrid
grid = ImageGrid(fig,111,nrows_ncols=(perRow,perColumn),axes_pad=padding,cbar_mode='single')
for i in range(0,np.shape(fields)[0]):
im = grid[i].imshow(fields[i],cmap=cmap);
grid.cbar_axes[0].colorbar(im)
mpl.title('%s Receptive Fields' % layer.name)
# old way
# fields2 = np.vstack([fields,np.zeros([perRow*perColumn-fields.shape[0]] + list(fields.shape[1:]))])
# tiled = []
# for i in range(0,perColumn*perRow,perColumn):
# tiled.append(np.hstack(fields2[i:i+perColumn]))
#
# tiled = np.vstack(tiled)
# mpl.figure(figOffset); mpl.clf(); mpl.imshow(tiled,cmap=cmap); mpl.title('%s Receptive Fields' % layer.name); mpl.colorbar();
mpl.figure(figOffset+1); mpl.clf(); mpl.imshow(np.sum(np.abs(fields),0),cmap=cmap); mpl.title('%s Total Absolute Input Dependency' % layer.name); mpl.colorbar()
示例6: plotOutput
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def plotOutput(layer,feed_dict,fieldShape=None,channel=None,figOffset=1,cmap=None):
# Output summary
try:
W = layer.output
except:
W = layer
wp = W.eval(feed_dict=feed_dict);
if len(np.shape(wp)) < 4: # Fully connected layer, has no shape
temp = np.zeros(np.product(fieldShape)); temp[0:np.shape(wp.ravel())[0]] = wp.ravel()
fields = np.reshape(temp,[1]+fieldShape)
else: # Convolutional layer already has shape
wp = np.rollaxis(wp,3,0)
features, channels, iy,ix = np.shape(wp)
if channel is not None:
fields = wp[:,channel,:,:]
else:
fields = np.reshape(wp,[features*channels,iy,ix])
perRow = int(math.floor(math.sqrt(fields.shape[0])))
perColumn = int(math.ceil(fields.shape[0]/float(perRow)))
fields2 = np.vstack([fields,np.zeros([perRow*perColumn-fields.shape[0]] + list(fields.shape[1:]))])
tiled = []
for i in range(0,perColumn*perRow,perColumn):
tiled.append(np.hstack(fields2[i:i+perColumn]))
tiled = np.vstack(tiled)
if figOffset is not None:
mpl.figure(figOffset); mpl.clf();
mpl.imshow(tiled,cmap=cmap); mpl.title('%s Output' % layer.name); mpl.colorbar();
示例7: plotFields
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def plotFields(layer,fieldShape=None,channel=None,maxFields=25,figName='ReceptiveFields',cmap=None,padding=0.01):
# Receptive Fields Summary
W = layer.W
wp = W.eval().transpose();
if len(np.shape(wp)) < 4: # Fully connected layer, has no shape
fields = np.reshape(wp,list(wp.shape[0:-1])+fieldShape)
else: # Convolutional layer already has shape
features, channels, iy, ix = np.shape(wp)
if channel is not None:
fields = wp[:,channel,:,:]
else:
fields = np.reshape(wp,[features*channels,iy,ix])
fieldsN = min(fields.shape[0],maxFields)
perRow = int(math.floor(math.sqrt(fieldsN)))
perColumn = int(math.ceil(fieldsN/float(perRow)))
fig = mpl.figure(figName); mpl.clf()
# Using image grid
from mpl_toolkits.axes_grid1 import ImageGrid
grid = ImageGrid(fig,111,nrows_ncols=(perRow,perColumn),axes_pad=padding,cbar_mode='single')
for i in range(0,fieldsN):
im = grid[i].imshow(fields[i],cmap=cmap);
grid.cbar_axes[0].colorbar(im)
mpl.title('%s Receptive Fields' % layer.name)
# old way
# fields2 = np.vstack([fields,np.zeros([perRow*perColumn-fields.shape[0]] + list(fields.shape[1:]))])
# tiled = []
# for i in range(0,perColumn*perRow,perColumn):
# tiled.append(np.hstack(fields2[i:i+perColumn]))
#
# tiled = np.vstack(tiled)
# mpl.figure(figOffset); mpl.clf(); mpl.imshow(tiled,cmap=cmap); mpl.title('%s Receptive Fields' % layer.name); mpl.colorbar();
mpl.figure(figName+' Total'); mpl.clf(); mpl.imshow(np.sum(np.abs(fields),0),cmap=cmap); mpl.title('%s Total Absolute Input Dependency' % layer.name); mpl.colorbar()
示例8: plotOutput
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def plotOutput(layer,feed_dict,fieldShape=None,channel=None,figOffset=1,cmap=None):
# Output summary
W = layer.output
wp = W.eval(feed_dict=feed_dict);
if len(np.shape(wp)) < 4: # Fully connected layer, has no shape
temp = np.zeros(np.product(fieldShape)); temp[0:np.shape(wp.ravel())[0]] = wp.ravel()
fields = np.reshape(temp,[1]+fieldShape)
else: # Convolutional layer already has shape
wp = np.rollaxis(wp,3,0)
features, channels, iy,ix = np.shape(wp)
if channel is not None:
fields = wp[:,channel,:,:]
else:
fields = np.reshape(wp,[features*channels,iy,ix])
perRow = int(math.floor(math.sqrt(fields.shape[0])))
perColumn = int(math.ceil(fields.shape[0]/float(perRow)))
fields2 = np.vstack([fields,np.zeros([perRow*perColumn-fields.shape[0]] + list(fields.shape[1:]))])
tiled = []
for i in range(0,perColumn*perRow,perColumn):
tiled.append(np.hstack(fields2[i:i+perColumn]))
tiled = np.vstack(tiled)
if figOffset is not None:
mpl.figure(figOffset); mpl.clf();
mpl.imshow(tiled,cmap=cmap); mpl.title('%s Output' % layer.name); mpl.colorbar();
示例9: contour_plot
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def contour_plot(func):
rose = func()
XS, YS = plt.meshgrid(np.linspace(-2, 2, 20), np.linspace(-2,2, 20));
ZS = np.array([rose(x1=x, x2=y).f_xy for x,y in zip(XS.flatten(),YS.flatten())]).reshape(XS.shape);
plt.contourf(XS, YS, ZS, 50);
plt.colorbar()
示例10: plot
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def plot(self, filename=None, vmin=None, vmax=None, cmap='jet_r'):
import pylab
pylab.clf()
pylab.imshow(-np.log10(self.results[self._start_y:,:]),
origin="lower",
aspect="auto", cmap=cmap, vmin=vmin, vmax=vmax)
pylab.colorbar()
# Fix xticks
XMAX = float(self.results.shape[1]) # The max integer on xaxis
xpos = list(range(0, int(XMAX), int(XMAX/5)))
xx = [int(this*100)/100 for this in np.array(xpos) / XMAX * self.duration]
pylab.xticks(xpos, xx, fontsize=16)
# Fix yticks
YMAX = float(self.results.shape[0]) # The max integer on xaxis
ypos = list(range(0, int(YMAX), int(YMAX/5)))
yy = [int(this) for this in np.array(ypos) / YMAX * self.sampling]
pylab.yticks(ypos, yy, fontsize=16)
#pylab.yticks([1000,2000,3000,4000], [5500,11000,16500,22000], fontsize=16)
#pylab.title("%s echoes" % filename.replace(".png", ""), fontsize=25)
pylab.xlabel("Time (seconds)", fontsize=25)
pylab.ylabel("Frequence (Hz)", fontsize=25)
pylab.tight_layout()
if filename:
pylab.savefig(filename)
示例11: examplify
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def examplify(cls, fname):
"""
example of how to use
"""
logger.info("examplify starts")
# model
model = MultiClassLogisticRegression(epsilon=0.01, n_scan = 100)
# learn
st = time.time()
model.learn(fname)
et = time.time()
print "learning time: %d [s]" % ((et - st)/1000)
# predict
y_pred = model.predict(fname)
# confusion matrix
y_label = np.loadtxt(fname, delimiter=" ")[:, 0]
cm = confusion_matrix(y_label, y_pred)
#pl.matshow(cm)
#pl.title('Confusion matrix')
#pl.colorbar()
#pl.ylabel('True label')
#pl.xlabel('Predicted label')
#pl.show()
print cm
print "accurary: %d [%%]" % (np.sum(cm.diagonal()) * 100.0/np.sum(cm))
logger.info("examplify finished")
开发者ID:kzky,项目名称:python-online-machine-learning-library,代码行数:34,代码来源:multiclass_logistic_regression.py
示例12: dendogram
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def dendogram(correlation_matrix,
save_as = '',
figsize=(50,50),
):
correlation_matrix = path.abspath(path.expanduser(correlation_matrix))
y = hier_clustering(correlation_matrix, method='centroid')
z = hier_clustering(y, orientation='right')
fig = pylab.figure(figsize=figsize)
ax_1 = fig.add_axes([0.1,0.1,0.2,0.8])
ax_1.set_xticks([])
ax_1.set_yticks([])
ax_2 = fig.add_axes([0.3,0.1,0.6,0.8])
index = z['leaves']
correlation_matrix = correlation_matrix[index,:]
correlation_matrix = correlation_matrix[:,index]
im = ax_2.matshow(correlation_matrix, aspect='auto', origin='lower')
ax_2.set_xticks([])
ax_2.set_yticks([])
ax_color = fig.add_axes([0.91,0.1,0.02,0.8])
colorbar = pylab.colorbar(im, cax=ax_color)
colorbar.ax.tick_params(labelsize=75)
# Display and save figure.
if(save_as):
fig.savefig(path.abspath(path.expanduser(save_as)))
示例13: plotHeatMap
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def plotHeatMap(data, col='KL without null', label=''):
#Compute and collate medians
sel_cols = [x for x in data.columns if col in x]
cmp_meds = data[sel_cols].median(axis=0)
samples = sortSampleNames(getUniqueSamples(sel_cols))
cell_lines = ['CHO', 'E14TG2A', 'BOB','RPE1', 'HAP1','K562','eCAS9','TREX2']
sample_idxs = [(cell_lines.index(parseSampleName(x)[0]),x) for x in getUniqueSamples(sel_cols)]
sample_idxs.sort()
samples = [x[1] for x in sample_idxs]
N = len(samples)
meds = np.zeros((N,N))
for colname in sel_cols:
dir1, dir2 = getDirsFromFilename(colname.split('$')[-1])
idx1, idx2 = samples.index(dir1), samples.index(dir2)
meds[idx1,idx2] = cmp_meds[colname]
meds[idx2,idx1] = cmp_meds[colname]
for i in range(N):
print(' '.join(['%.2f' % x for x in meds[i,:]]))
print( np.median(meds[:,:-4],axis=0))
#Display in Heatmap
PL.figure(figsize=(5,5))
PL.imshow(meds, cmap='hot_r', vmin = 0.0, vmax = 3.0, interpolation='nearest')
PL.colorbar()
PL.xticks(range(N))
PL.yticks(range(N))
PL.title("Median KL") # between %d mutational profiles (for %s with >%d mutated reads)" % (col, len(data), label, MIN_READS))
ax1 = PL.gca()
ax1.set_yticklabels([getSimpleName(x) for x in samples], rotation='horizontal')
ax1.set_xticklabels([getSimpleName(x) for x in samples], rotation='vertical')
PL.subplots_adjust(left=0.25,right=0.95,top=0.95, bottom=0.25)
PL.show(block=False)
saveFig('median_kl_heatmap_cell_lines')
示例14: nice_imshow
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def nice_imshow(ax, data, vmin=None, vmax=None, cmap=None):
"""Wrapper around pl.imshow"""
if cmap is None:
cmap = cm.jet
if vmin is None:
vmin = data.min()
if vmax is None:
vmax = data.max()
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
im = ax.imshow(data, vmin=vmin, vmax=vmax, interpolation='nearest', cmap=cmap)
pl.colorbar(im, cax=cax)
示例15: plot_confusion_matrix
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import colorbar [as 别名]
def plot_confusion_matrix(cm, title='Confusion matrix', cmap=plt.cm.Blues):
plt.imshow(cm, interpolation='nearest', cmap=cmap)
plt.title(title)
plt.colorbar()
tick_marks = np.arange(len(iris.target_names))
plt.xticks(tick_marks, iris.target_names, rotation=45)
plt.yticks(tick_marks, iris.target_names)
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')