Python matplotlib.pylab 模块,get_cmap() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用matplotlib.pylab.get_cmap()

项目:gps    作者:cbfinn    | 项目源码 | 文件源码
def init(self, data_len):
        """
        Initialize plots based off the length of the data array.
        """
        self._t = 0
        self._data_len = data_len
        self._data = np.empty((0, data_len))

        cm = plt.get_cmap('spectral')
        self._plots = []
        for i in range(data_len):
            color = cm(1.0 * i / data_len)
            alpha = self._alphas[i] if self._alphas is not None else 1.0
            label = self._labels[i] if self._labels is not None else str(i)
            self._plots.append(
                self._ax.plot([], [], color=color, alpha=alpha, label=label)[0]
            )
        self._ax.set_xlim(0, self._time_window)
        self._ax.set_ylim(0, 1)
        self._ax.legend(loc='upper left', bbox_to_anchor=(0, 1.15))

        self._init = True
项目:options    作者:mcmachado    | 项目源码 | 文件源码
def plotValueFunction(self, valueFunction, prefix):
        '''3d plot of a value function.'''
        fig, ax = plt.subplots(subplot_kw = dict(projection = '3d'))
        X, Y = np.meshgrid(np.arange(self.numCols), np.arange(self.numRows))
        Z = valueFunction.reshape(self.numRows, self.numCols)

        for i in xrange(len(X)):
            for j in xrange(len(X[i])/2):
                tmp = X[i][j]
                X[i][j] = X[i][len(X[i]) - j - 1]
                X[i][len(X[i]) - j - 1] = tmp

        my_col = cm.jet(np.random.rand(Z.shape[0],Z.shape[1]))

        ax.plot_surface(X, Y, Z, rstride = 1, cstride = 1,
            cmap = plt.get_cmap('jet'))
        plt.gca().view_init(elev=30, azim=30)
        plt.savefig(self.outputPath + prefix + 'value_function.png')
        plt.close()
项目:gps_superball_public    作者:young-geng    | 项目源码 | 文件源码
def init(self, data_len):
        """
        Initialize plots based off the length of the data array.
        """
        self._t = 0
        self._data_len = data_len
        self._data = np.empty((0, data_len))

        cm = plt.get_cmap('spectral')
        self._plots = []
        for i in range(data_len):
            color = cm(1.0 * i / data_len)
            alpha = self._alphas[i] if self._alphas is not None else 1.0
            label = self._labels[i] if self._labels is not None else str(i)
            self._plots.append(
                self._ax.plot([], [], color=color, alpha=alpha, label=label)[0]
            )
        self._ax.set_xlim(0, self._time_window)
        self._ax.set_ylim(0, 1)
        self._ax.legend(loc='upper left', bbox_to_anchor=(0, 1.15))

        self._init = True
项目:MDI    作者:rafaelvalle    | 项目源码 | 文件源码
def discrete_cmap(N, base_cmap=None):
    """Create an N-bin discrete colormap from the specified input map"""

    # Note that if base_cmap is a string or None, you can simply do
    #    return plt.cm.get_cmap(base_cmap, N)
    # The following works for string, None, or a colormap instance:

    base = plt.cm.get_cmap(base_cmap)
    color_list = base(np.linspace(0, 1, N))
    cmap_name = base.name + str(N)
    return base.from_list(cmap_name, color_list, N)
项目:options    作者:mcmachado    | 项目源码 | 文件源码
def plotBasisFunctions(self, eigenvalues, eigenvectors):
        '''3d plot of the basis function. Right now I am plotting eigenvectors,
           so each coordinate of the eigenvector correspond to the value to be
           plotted for the correspondent state.''' 
        for i in xrange(len(eigenvalues)):  
            fig, ax = plt.subplots(subplot_kw = dict(projection = '3d'))
            X, Y = np.meshgrid(np.arange(self.numRows), np.arange(self.numCols))
            Z = eigenvectors[:,i].reshape(self.numCols, self.numRows)

            for ii in xrange(len(X)):
                for j in xrange(len(X[ii])/2):
                    tmp = X[ii][j]
                    X[ii][j] = X[ii][len(X[ii]) - j - 1]
                    X[ii][len(X[ii]) - j - 1] = tmp

            my_col = cm.jet(np.random.rand(Z.shape[0],Z.shape[1]))

            ax.plot_surface(X, Y, Z, rstride = 1, cstride = 1,
                cmap = plt.get_cmap('jet'))
            plt.gca().view_init(elev=30, azim=30)
            plt.savefig(self.outputPath + str(i) + '_eig' + '.png')
            plt.close()


        plt.plot(eigenvalues, 'o')
        plt.savefig(self.outputPath + 'eigenvalues.png')
项目:MDI    作者:rafaelvalle    | 项目源码 | 文件源码
def plot_2d(params_dir):
    model_dirs = [name for name in os.listdir(params_dir)
                  if os.path.isdir(os.path.join(params_dir, name))]
    if len(model_dirs) == 0:
      model_dirs = [params_dir]


    colors = plt.get_cmap('plasma')
    plt.figure(figsize=(20, 10))
    ax = plt.subplot(111)
    ax.set_xlabel('Learning Rate')
    ax.set_ylabel('Error rate')

    i = 0
    for model_dir in model_dirs:
        model_df = pd.DataFrame()
        for param_path in glob.glob(os.path.join(params_dir,
                                                 model_dir) + '/*.h5'):
            param = dd.io.load(param_path)
            gd = {'learning rate': param['hyperparameters']['learning_rate'],
                  'momentum': param['hyperparameters']['momentum'],
                  'dropout': param['hyperparameters']['dropout'],
                  'val. objective': param['best_epoch']['validate_objective']}
            model_df = model_df.append(pd.DataFrame(gd, index=[0]),
                                       ignore_index=True)
        if i != len(model_dirs) - 1:
            ax.scatter(model_df['learning rate'],
                       model_df['val. objective'],
                       s=128,
                       marker=(i+3, 0),
                       edgecolor='black',
                       linewidth=model_df['dropout'],
                       label=model_dir,
                       c=model_df['momentum'],
                       cmap=colors)
        else:
            im = ax.scatter(model_df['learning rate'],
                            model_df['val. objective'],
                            s=128,
                            marker=(i+3, 0),
                            edgecolor='black',
                            linewidth=model_df['dropout'],
                            label=model_dir,
                            c=model_df['momentum'],
                            cmap=colors)
        i += 1

    plt.colorbar(im, label='Momentum')
    plt.legend()
    plt.show()
    plt.savefig('{}.eps'.format(os.path.join(IMAGES_DIRECTORY, 'params2d')), format='eps', dpi=1000)
    plt.close()