Python matplotlib.cm 模块,cool() 实例源码

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

项目:voxcelchain    作者:hiroaki-kaneda    | 项目源码 | 文件源码
def conv1(model):
    n1, n2, x, y, z = model.conv1.W.shape
    fig = plt.figure()
    for nn in range(0, n1):
        ax = fig.add_subplot(4, 5, nn+1, projection='3d')
        ax.set_xlim(0.0, x)
        ax.set_ylim(0.0, y)
        ax.set_zlim(0.0, z)
        ax.set_xticklabels([])
        ax.set_yticklabels([])
        ax.set_zticklabels([])
        for xx in range(0, x):
            for yy in range(0, y):
                for zz in range(0, z):
                    max = np.max(model.conv1.W.data[nn, :])
                    min = np.min(model.conv1.W.data[nn, :])
                    step = (max - min) / 1.0
                    C = (model.conv1.W.data[nn, 0, xx, yy, zz] - min) / step
                    color = cm.cool(C)
                    C = abs(1.0 - C)
                    ax.plot(np.array([xx]), np.array([yy]), np.array([zz]), "o", color=color, ms=7.0*C, mew=0.1)

    plt.savefig("result/graph_conv1.png")
项目:voxcelchain    作者:hiroaki-kaneda    | 项目源码 | 文件源码
def conv2(model):
    n1, n2, x, y, z = model.conv2.W.shape
    for nn in range(0, n1):
        fig = plt.figure()
        for mm in range(0, n2):
            ax = fig.add_subplot(4, 5, mm + 1, projection='3d')
            ax.set_xlim(0.0, x)
            ax.set_ylim(0.0, y)
            ax.set_zlim(0.0, z)
            ax.set_xticklabels([])
            ax.set_yticklabels([])
            ax.set_zticklabels([])

            for xx in range(0, x):
                for yy in range(0, y):
                    for zz in range(0, z):
                        max = np.max(model.conv2.W.data[nn, mm:])
                        min = np.min(model.conv2.W.data[nn, mm:])
                        step = (max - min) / 1.0
                        C = (model.conv2.W.data[nn, mm, xx, yy, zz] - min) / step
                        color = cm.cool(C)
                        C = abs(1.0-C)
                        ax.plot(np.array([xx]), np.array([yy]), np.array([zz]), "o", color=color, ms=7.0 * C, mew=0.1)

        plt.savefig("result/graph_conv2_" + str(nn) +  ".png")
项目:bolib    作者:ibaidev    | 项目源码 | 文件源码
def plot_3d(objective_function, length=20):
    """
    Plot 3D functions

    :param objective_function:
    :type objective_function:
    :param length:
    :type length:
    :return:
    :rtype:
    """
    bounds = objective_function.get_bounds()

    if len(bounds) != 2:
        return

    x_grid = np.linspace(bounds[0][0], bounds[0][1], length)
    y_grid = np.linspace(bounds[1][0], bounds[1][1], length)
    x_grid, y_grid = np.meshgrid(x_grid, y_grid)
    grid = np.vstack((x_grid.flatten(), y_grid.flatten())).T
    z_points = objective_function.evaluate(grid)
    z_points = z_points.reshape(length, length)

    fig = pyplot.figure()
    axis = fig.gca(projection='3d')

    surf = axis.plot_surface(x_grid, y_grid,
                             z_points, rstride=1, cstride=1,
                             cmap=cm.cool, linewidth=0, antialiased=False,
                             alpha=0.3)
    axis.contour(x_grid.tolist(), y_grid.tolist(), z_points.tolist(),
                 zdir='z', offset=z_points.min(), cmap=cm.cool)

    axis.set_xlim(bounds[0][0], bounds[0][1])
    axis.set_ylim(bounds[1][0], bounds[1][1])
    pyplot.title(objective_function.__class__.__name__)
    axis.zaxis.set_major_locator(LinearLocator(10))
    axis.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
    fig.colorbar(surf, shrink=0.5, aspect=5)

    pyplot.show()
项目:AutoEncoder    作者:np2lkoo    | 项目源码 | 文件源码
def report_w3d(self, my_ae):
        for period in range(np.int(np.log2(my_ae.epoch_limit) + 1)):
            targetW = my_ae.get_W1(period)
            x = range(27)
            y = range(27)

        ax3d = plt.subplot(self.gs[period, 2])
        X, Y = np.meshgrid(x, y)
        Z = targetW[2][X + (784 - 28) - Y * 28]
        fig = plt.figure()
        #ax = Axes3D(fig)
        ax = fig.gca(projection='3d')
        # ax.plot_wireframe(X,Y,Z)
        plt.cool()
        cset = ax.contourf(X, Y, Z, zdir='z', offset=-4, cmap=cm.coolwarm)
        cset = ax.contourf(X, Y, Z, zdir='x', offset=-1, cmap=cm.cool)
        cset = ax.contourf(X, Y, Z, zdir='y', offset=-1, cmap=cm.cool)
        ax.plot_surface(X, Y, Z, rstride=1, cstride=1, alpha=0.3)
        # ax.contourf3D(X,Y,Z)
        # surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
        #                       linewidth=0, antialiased=False)
        # fig.colorbar(surf, shrink=0.5, aspect=5)
        ax.view_init(20, 30)
        ax.set_xlabel('X')
        ax.set_xlim(0, 27)
        ax.set_ylabel('Y')
        ax.set_ylim(0, 27)
        ax.set_zlabel('Z')
        ax.set_zlim(-4, 3)
        plt.show()
项目:accpy    作者:kramerfelix    | 项目源码 | 文件源码
def tuneplot(ax1, ax2, data, particleIDs='allIDs', integer=1, addsub=add,
             clipint=True, showlost=False, QQ='Qx', ms=1, clip=[0], showfit=False):
    particleIDs = data[particleIDs]
    if not showlost:
    lost = data['lost'][:, 0]
    clip = concatenate([clip, lost])
    particleIDs = delete(particleIDs, clip)
    Q = addsub(integer, data[QQ][particleIDs])
    if clipint:
        zeroQ = find(logical_or(logical_or(Q == 0.0, Q == 1.0), Q == 0.5))
        if len(zeroQ) > 0:  # trim reference particle with zero tune
            Q = delete(Q, zeroQ)
            particleIDs = delete(particleIDs, zeroQ)
    Qmin, Qmax = nanmin(Q), nanmax(Q)
    Qdif = Qmax - Qmin
    if Qdif == 0.0:
        Qmin -= Qmin/1e4
        Qmax += Qmax/1e4
        Qdif = Qmax - Qmin
    colors = cool((Q - Qmin) / Qdif)
    for i, ID in enumerate(particleIDs):
        ax1.plot(data['x'][:, ID]*1e3, data['xp'][:, ID]*1e3, '.', c=colors[i], ms=ms)
    if showlost:
        for ID in lost:
            ax1.plot(data['x'][:, ID]*1e3, data['xp'][:, ID]*1e3, '.', c='gray', ms=ms)
    sm = ScalarMappable(cmap=rainbow, norm=Normalize(vmin=Qmin, vmax=Qmax))
    sm._A = []
    ax1.set_xlabel(r'Position $x$ / (mm)')
    ax1.set_ylabel(r'Angle $x^\prime$ / (mrad)')
    emittance = data['A'][particleIDs]/pi
    action = emittance/2

    # tune shift with action
    fitfun = lambda x, a, b: a + b*x
    popt, pcov = curve_fit(fitfun, action, Q)
    perr = sqrt(diag(pcov))
    action2 = linspace(nanmin(action), nanmax(action), 1000)
    fit1 = fitfun(action2, *popt)
    print(popt[1]*1e-6*1250)

    for i, ID in enumerate(particleIDs):
        ax2.plot(action[i]*1e6, Q[i], 'o', c=colors[i], ms=ms + 1)
    if showfit:
    ax2.plot(action2*1e6, fit1, '-k', lw=1, label=r'fit with $TSWA=${:.4}$\pm${:.1} (kHz mm$^-$$^2$mrad$^-$$^2$)'.format(popt[1]*1e-6*1250, perr[1]*1e-6*1250))
#    leg = ax2.legend()
#    leg.get_frame().set_alpha(0)
    ax2.set_ylim([Qmin, Qmax])
#    ax2.yaxis.tick_right()
    ax2.set_ylabel(r'Fractional Tune $dQ$')
#    ax2.yaxis.set_label_position('right')
    ax2.set_xlabel(r'Action $J_x$ / (mm$\cdot$mrad)')
    tight_layout()
    return