本文整理汇总了Python中matplotlib.cm.rainbow方法的典型用法代码示例。如果您正苦于以下问题:Python cm.rainbow方法的具体用法?Python cm.rainbow怎么用?Python cm.rainbow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.cm
的用法示例。
在下文中一共展示了cm.rainbow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_buffer
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def draw_buffer(self):
self.buffer_figure, self.buffer_ax = plt.subplots()
self.lineIN, = self.buffer_ax.plot([1] * 2, [1] * 2, color='#000000', ls="None", label="IN", marker='o',
animated=True)
self.lineOUT, = self.buffer_ax.plot([1] * 2, [1] * 2, color='#CCCCCC', ls="None", label="OUT", marker='o',
animated=True)
self.buffer_figure.suptitle("Buffer Status", size=16)
plt.legend(loc=2, numpoints=1)
total_peers = self.number_of_monitors + self.number_of_peers + self.number_of_malicious
self.buffer_colors = cm.rainbow(np.linspace(0, 1, total_peers))
plt.axis([0, total_peers + 1, 0, self.get_buffer_size()])
plt.xticks(range(0, total_peers + 1, 1))
self.buffer_order = {}
self.buffer_index = 1
self.buffer_labels = self.buffer_ax.get_xticks().tolist()
plt.grid()
self.buffer_figure.canvas.draw()
示例2: ptf
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def ptf(self):
"""
Phase transfer function
"""
PSF = self.__psfcaculator__()
PTF = __fftshift__(__fft2__(PSF))
PTF = __np__.angle(PTF)
b = 400
R = (200)**2
for i in range(b):
for j in range(b):
if (i-b/2)**2+(j-b/2)**2>R:
PTF[i][j] = 0
__plt__.imshow(abs(PTF),cmap=__cm__.rainbow)
__plt__.colorbar()
__plt__.show()
return 0
示例3: plot_shape
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def plot_shape(xys, z1, z2, ax, scale, scatter, symm_axis, **kwargs):
# mx = max([y for (x, y) in m])
# mn = min([y for (x, y) in m])
xscl = scale# / (mx - mn)
yscl = scale# / (mx - mn)
# ax.scatter(z1, z2)
if scatter:
if 'c' not in kwargs:
kwargs['c'] = cm.rainbow(np.linspace(0,1,xys.shape[0]))
# ax.plot( *zip(*[(x * xscl + z1, y * yscl + z2) for (x, y) in xys]), lw=.2, c='b')
ax.scatter( *zip(*[(x * xscl + z1, y * yscl + z2) for (x, y) in xys]), edgecolors='none', **kwargs)
else:
ax.plot( *zip(*[(x * xscl + z1, y * yscl + z2) for (x, y) in xys]), **kwargs)
if symm_axis == 'y':
# ax.plot( *zip(*[(-x * xscl + z1, y * yscl + z2) for (x, y) in xys]), lw=.2, c='b')
plt.fill_betweenx( *zip(*[(y * yscl + z2, -x * xscl + z1, x * xscl + z1)
for (x, y) in xys]), color='gray', alpha=.2)
elif symm_axis == 'x':
# ax.plot( *zip(*[(x * xscl + z1, -y * yscl + z2) for (x, y) in xys]), lw=.2, c='b')
plt.fill_between( *zip(*[(x * xscl + z1, -y * yscl + z2, y * yscl + z2)
for (x, y) in xys]), color='gray', alpha=.2)
示例4: plot_clustered_data
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def plot_clustered_data(points, c_means, c_assignments):
"""Plots the cluster-colored data and the cluster means"""
colors = cm.rainbow(np.linspace(0, 1, CLUSTERS))
for cluster, color in zip(range(CLUSTERS), colors):
c_points = points[c_assignments == cluster]
plt.plot(c_points[:, 0], c_points[:, 1], ".", color=color, zorder=0)
plt.plot(c_means[cluster, 0], c_means[cluster, 1], ".", color="black", zorder=1)
plt.show()
# PREPARING DATA
# generating DATA_POINTS points from a GMM with CLUSTERS components
示例5: cluster_body
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def cluster_body(net, cluster_data, device, save_path):
data, characters = cluster_data[0], cluster_data[2]
data = data[:, :, 0, :, :]
# data = data.reshape(-1, data.shape[2], data.shape[3], data.shape[4])
nr_mv, nr_char = data.shape[0], data.shape[1]
labels = np.arange(0, nr_char).reshape(1, -1)
labels = np.tile(labels, (nr_mv, 1)).reshape(-1)
if hasattr(net, 'static_encoder'):
features = net.static_encoder(data.contiguous().view(-1, data.shape[2], data.shape[3])[:, :-2, :].to(device))
else:
features = net.body_encoder(data.contiguous().view(-1, data.shape[2], data.shape[3])[:, :-2, :].to(device))
features = features.detach().cpu().numpy().reshape(features.shape[0], -1)
features_2d = tsne_on_pca(features, is_PCA=False)
features_2d = features_2d.reshape(nr_mv, nr_char, -1)
plt.figure(figsize=(7, 4))
colors = cm.rainbow(np.linspace(0, 1, nr_char))
for i in range(nr_char):
x = features_2d[:, i, 0]
y = features_2d[:, i, 1]
plt.scatter(x, y, c=colors[i], label=characters[i])
plt.legend(bbox_to_anchor=(1.04, 1), borderaxespad=0)
plt.tight_layout(rect=[0,0,0.75,1])
plt.savefig(save_path)
示例6: cluster_view
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def cluster_view(net, cluster_data, device, save_path):
data, views = cluster_data[0], cluster_data[3]
idx = np.random.randint(data.shape[1] - 1) # np.linspace(0, data.shape[1] - 1, 4, dtype=int).tolist()
data = data[:, idx, :, :, :]
nr_mc, nr_view = data.shape[0], data.shape[1]
labels = np.arange(0, nr_view).reshape(1, -1)
labels = np.tile(labels, (nr_mc, 1)).reshape(-1)
if hasattr(net, 'static_encoder'):
features = net.static_encoder(data.contiguous().view(-1, data.shape[2], data.shape[3])[:, :-2, :].to(device))
else:
features = net.view_encoder(data.contiguous().view(-1, data.shape[2], data.shape[3])[:, :-2, :].to(device))
features = features.detach().cpu().numpy().reshape(features.shape[0], -1)
features_2d = tsne_on_pca(features, is_PCA=False)
features_2d = features_2d.reshape(nr_mc, nr_view, -1)
plt.figure(figsize=(7, 4))
colors = cm.rainbow(np.linspace(0, 1, nr_view))
for i in range(nr_view):
x = features_2d[:, i, 0]
y = features_2d[:, i, 1]
plt.scatter(x, y, c=colors[i], label=views[i])
plt.legend(bbox_to_anchor=(1.04, 1), borderaxespad=0)
plt.tight_layout(rect=[0, 0, 0.75, 1])
plt.savefig(save_path)
示例7: cluster_motion
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def cluster_motion(net, cluster_data, device, save_path, nr_anims=15, mode='both'):
data, animations = cluster_data[0], cluster_data[1]
idx = np.linspace(0, data.shape[0] - 1, nr_anims, dtype=int).tolist()
data = data[idx]
animations = animations[idx]
if mode == 'body':
data = data[:, :, 0, :, :].reshape(nr_anims, -1, data.shape[3], data.shape[4])
elif mode == 'view':
data = data[:, 3, :, :, :].reshape(nr_anims, -1, data.shape[3], data.shape[4])
else:
data = data[:, :4, ::2, :, :].reshape(nr_anims, -1, data.shape[3], data.shape[4])
nr_anims, nr_cv = data.shape[:2]
labels = np.arange(0, nr_anims).reshape(-1, 1)
labels = np.tile(labels, (1, nr_cv)).reshape(-1)
features = net.mot_encoder(data.contiguous().view(-1, data.shape[2], data.shape[3]).to(device))
features = features.detach().cpu().numpy().reshape(features.shape[0], -1)
features_2d = tsne_on_pca(features)
features_2d = features_2d.reshape(nr_anims, nr_cv, -1)
if features_2d.shape[1] < 5:
features_2d = np.tile(features_2d, (1, 2, 1))
plt.figure(figsize=(8, 4))
colors = cm.rainbow(np.linspace(0, 1, nr_anims))
for i in range(nr_anims):
x = features_2d[i, :, 0]
y = features_2d[i, :, 1]
plt.scatter(x, y, c=colors[i], label=animations[i])
plt.legend(bbox_to_anchor=(1.04, 1), borderaxespad=0)
plt.tight_layout(rect=[0,0,0.8,1])
plt.savefig(save_path)
示例8: draw_buffer
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def draw_buffer(self):
self.buff_win = pg.GraphicsLayoutWidget()
self.buff_win.setWindowTitle('Buffer Status')
self.buff_win.resize(800, 700)
self.total_peers = self.number_of_monitors + self.number_of_peers + self.number_of_malicious
self.p4 = self.buff_win.addPlot()
self.p4.showGrid(x=True, y=True, alpha=100) # To show grid lines across x axis and y axis
leftaxis = self.p4.getAxis('left') # get left axis i.e y axis
leftaxis.setTickSpacing(5, 1) # to set ticks at a interval of 5 and grid lines at 1 space
# Get different colors using matplotlib library
if self.total_peers < 8:
colors = cm.Set2(np.linspace(0, 1, 8))
elif self.total_peers < 12:
colors = cm.Set3(np.linspace(0, 1, 12))
else:
colors = cm.rainbow(np.linspace(0, 1, self.total_peers+1))
self.QColors = [pg.hsvColor(color[0], color[1], color[2], color[3])
for color in colors] # Create QtColors, each color would represent a peer
self.Data = [] # To represent buffer out i.e outgoing data from buffer
self.OutData = [] # To represent buffer in i.e incoming data in buffer
# a single line would reperesent a single color or peer, hence we would not need to pass a list of brushes
self.lineIN = [None]*self.total_peers
for ix in range(self.total_peers):
self.lineIN[ix] = self.p4.plot(pen=(None), symbolBrush=self.QColors[ix], name='IN', symbol='o', clear=False)
self.Data.append(set())
self.OutData.append(set())
# similiarly one line per peer to represent outgoinf data from buffer
self.lineOUT = self.p4.plot(pen=(None), symbolBrush=mkColor('#CCCCCC'), name='OUT', symbol='o', clear=False)
self.p4.setRange(xRange=[0, self.total_peers], yRange=[0, self.get_buffer_size()])
self.buff_win.show() # To actually show create window
self.buffer_order = {}
self.buffer_index = 0
self.buffer_labels = []
self.lastUpdate = pg.ptime.time()
self.avgFps = 0.0
示例9: ptf
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def ptf(self):
"""
Phase transfer function
"""
PSF = self.__psfcaculator__()
PTF = __fftshift__(__fft2__(PSF))
PTF = __np__.angle(PTF)
l1 = 100
d = 400
A = __np__.zeros([d,d])
A[d//2-l1//2+1:d//2+l1//2+1,d//2-l1//2+1:d//2+l1//2+1] = PTF[d//2-l1//2+1:d//2+l1//2+1,d//2-l1//2+1:d//2+l1//2+1]
__plt__.imshow(abs(A),cmap=__cm__.rainbow)
__plt__.colorbar()
__plt__.show()
return 0
示例10: plot_with_labels
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def plot_with_labels(lowDWeights, labels,sz):
plt.cla()
X_t0,Y_t0 = lowDWeights[0][:,0],lowDWeights[0][:,1]
X_t1,Y_t1 = lowDWeights[1][:,0],lowDWeights[1][:,1]
for idx,(x_t0,y_t0,x_t1,y_t1,lab) in enumerate(zip(X_t0,Y_t0,X_t1,Y_t1,labels)):
c = cm.rainbow(int(255 * idx/sz))
plt.text(x_t0,y_t0,lab,backgroundcolor=c,fontsize=9)
plt.text(x_t1,y_t1,lab,backgroundcolor=c,fontsize=9)
plt.xlim(X_t0.min(), X_t0.max());plt.ylim(Y_t0.min(), Y_t1.max());
plt.title('Visualize last layer');plt.show();plt.pause(0.01)
#for x, y, s in zip(X, Y, labels):
#c = cm.rainbow(int(255 * s / 9)); plt.text(x, y, s, backgroundcolor=c, fontsize=9)
示例11: plot_with_labels_feat_cat
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def plot_with_labels_feat_cat(lowDWeights, labels,save_dir,title):
plt.cla()
X,Y = lowDWeights[:,0],lowDWeights[:,1]
#plt.scatter(X,Y)
for idx,(x,y,lab) in enumerate(zip(X,Y,labels)):
color = cm.rainbow(int(255 * lab/2))
#plt.scatter(x,y,color)
plt.text(x,y,lab,backgroundcolor=color,fontsize=0)
plt.xlim(X.min() *2 , X.max() *2);plt.ylim(Y.min()*2, Y.max()*2)
plt.title(title)
#plt.show();plt.pause(0.01)
plt.savefig(save_dir)
print save_dir
#for x, y, s in zip(X, Y, labels):
#c = cm.rainbow(int(255 * s / 9)); plt.text(x, y, s, backgroundcolor=c, fontsize=9)
示例12: plot_with_labels_feat_cat_without_text
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def plot_with_labels_feat_cat_without_text(lowDWeights, labels,save_dir):
plt.cla()
X,Y = lowDWeights[:,0],lowDWeights[:,1]
for idx,(x,y,lab) in enumerate(zip(X,Y,labels)):
#c = cm.rainbow(int(255 * lab/2))
if lab == 0:
plt.plot(x,y,'b')
if lab == 1:
plt.plot(x,y,'r')
#plt.text(x,y,lab,backgroundcolor=c,fontsize=9)
plt.xlim(X.min() *2 , X.max() *2);plt.ylim(Y.min()*2, Y.max()*2)
plt.title('Visualize last layer')
#plt.show();plt.pause(0.01)
plt.savefig(save_dir)
print save_dir
示例13: rainbow_gradient
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def rainbow_gradient(cls, n):
cmap = cm.rainbow(np.linspace(0.0, 1.0, n))
R = list(map(lambda x: math.floor(x * 255), cmap[:, 0]))
G = list(map(lambda x: math.floor(x * 255), cmap[:, 1]))
B = list(map(lambda x: math.floor(x * 255), cmap[:, 2]))
return cls.__color_dict(list(zip(B, G, R)))
示例14: color_scatter
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def color_scatter(ax, xs, ys):
colors = cm.rainbow(np.linspace(0, 1, len(ys)))
for x, y, c in zip(xs, ys, colors):
ax.scatter(x, y, color=c)
示例15: plot_reduced_transferValues
# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import rainbow [as 别名]
def plot_reduced_transferValues(transferValues, cls_integers):
# Create a color-map with a different color for each class.
c_map = color_map.rainbow(np.linspace(0.0, 1.0, num_classes))
# Getting the color for each sample.
colors = c_map[cls_integers]
# Getting the x and y values.
x_val = transferValues[:, 0]
y_val = transferValues[:, 1]
# Plot the transfer values in a scatter plot
plt.scatter(x_val, y_val, color=colors)
plt.show()
开发者ID:PacktPublishing,项目名称:Deep-Learning-By-Example,代码行数:16,代码来源:cifar_10_revisted_transfer_learning.py