Python matplotlib.cm.rainbow() Examples

The following are 17 code examples for showing how to use matplotlib.cm.rainbow(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module matplotlib.cm , or try the search function .

Example 1
Project: simulator   Author: P2PSP   File: play.py    License: GNU General Public License v3.0 6 votes vote down vote up
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() 
Example 2
Project: opticspy   Author: Sterncat   File: zernike.py    License: MIT License 6 votes vote down vote up
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 
Example 3
Project: airfoil-opt-gan   Author: IDEALLab   File: shape_plot.py    License: MIT License 6 votes vote down vote up
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) 
Example 4
Project: tf-example-models   Author: aakhundov   File: tf_kmeans.py    License: Apache License 2.0 5 votes vote down vote up
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 
Example 5
Project: 2D-Motion-Retargeting   Author: ChrisWu1997   File: cluster.py    License: MIT License 5 votes vote down vote up
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) 
Example 6
Project: 2D-Motion-Retargeting   Author: ChrisWu1997   File: cluster.py    License: MIT License 5 votes vote down vote up
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) 
Example 7
Project: 2D-Motion-Retargeting   Author: ChrisWu1997   File: cluster.py    License: MIT License 5 votes vote down vote up
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) 
Example 8
Project: simulator   Author: P2PSP   File: play.py    License: GNU General Public License v3.0 5 votes vote down vote up
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 
Example 9
Project: opticspy   Author: Sterncat   File: zernike_rec.py    License: MIT License 5 votes vote down vote up
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 
Example 10
Project: SceneChangeDet   Author: gmayday1997   File: tsne_visual.py    License: MIT License 5 votes vote down vote up
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) 
Example 11
Project: SceneChangeDet   Author: gmayday1997   File: tsne_visual.py    License: MIT License 5 votes vote down vote up
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) 
Example 12
Project: SceneChangeDet   Author: gmayday1997   File: tsne_visual.py    License: MIT License 5 votes vote down vote up
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 
Example 13
Project: CvStudio   Author: haruiz   File: color_utilities.py    License: MIT License 5 votes vote down vote up
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))) 
Example 14
Project: autograd   Author: HIPS   File: ica.py    License: MIT License 5 votes vote down vote up
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) 
Example 15
Project: Deep-Learning-By-Example   Author: PacktPublishing   File: cifar_10_revisted_transfer_learning.py    License: MIT License 5 votes vote down vote up
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() 
Example 16
Project: MachineLearning_TensorFlow   Author: lawlite19   File: transferLearning_inceptionModel.py    License: MIT License 5 votes vote down vote up
def plot_scatter(values, cls):
    from matplotlib import cm as cm
    cmap = cm.rainbow(np.linspace(0.0, 1.0, num_classes))
    colors = cmap[cls]
    x = values[:, 0]
    y = values[:, 1]
    plt.scatter(x, y, color=colors)
    plt.show() 
Example 17
Project: spotpy   Author: thouska   File: analyser.py    License: MIT License 4 votes vote down vote up
def plot_heatmap_griewank(results,algorithms, fig_name='heatmap_griewank.png'):
    """Example Plot as seen in the SPOTPY Documentation"""
    import matplotlib.pyplot as plt

    from matplotlib import ticker
    from matplotlib import cm
    font = {'family' : 'calibri',
        'weight' : 'normal',
        'size'   : 20}
    plt.rc('font', **font)
    subplots=len(results)
    xticks=[-40,0,40]
    yticks=[-40,0,40]
    fig=plt.figure(figsize=(16,6))
    N = 2000
    x = np.linspace(-50.0, 50.0, N)
    y = np.linspace(-50.0, 50.0, N)

    x, y = np.meshgrid(x, y)

    z=1+ (x**2+y**2)/4000 - np.cos(x/np.sqrt(2))*np.cos(y/np.sqrt(3))

    cmap = plt.get_cmap('autumn')

    rows=2.0
    for i in range(subplots):
        amount_row = int(np.ceil(subplots/rows))
        ax = plt.subplot(rows, amount_row, i+1)
        CS = ax.contourf(x, y, z,locator=ticker.LogLocator(),cmap=cm.rainbow)

        ax.plot(results[i]['par0'],results[i]['par1'],'ko',alpha=0.2,markersize=1.9)
        ax.xaxis.set_ticks([])
        if i==0:
            ax.set_ylabel('y')
        if i==subplots/rows:
            ax.set_ylabel('y')
        if i>=subplots/rows:
            ax.set_xlabel('x')
            ax.xaxis.set_ticks(xticks)

        if i!=0 and i!=subplots/rows:
            ax.yaxis.set_ticks([])


        ax.set_title(algorithms[i])

    fig.savefig(fig_name, bbox_inches='tight')