Python matplotlib.pyplot 模块,gray() 实例源码

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

项目:Google-QuickDraw    作者:ankonzoid    | 项目源码 | 文件源码
def plot_labeled_images_random(image_list, label_list, categories, n, title_str, ypixels, xpixels, seed, filename):
    random.seed(seed)
    index_sample = random.sample(range(len(image_list)), n)
    plt.figure(figsize=(2*n, 2))
    #plt.suptitle(title_str)
    for i, ind in enumerate(index_sample):
        ax = plt.subplot(1, n, i + 1)
        plt.imshow(image_list[ind].reshape(ypixels, xpixels))
        plt.gray()
        ax.set_title(categories[label_list[ind]], fontsize=20)
        ax.get_xaxis().set_visible(False); ax.get_yaxis().set_visible(False)
    if 1:
        pylab.savefig(filename, bbox_inches='tight')
    else:
        plt.show()

# plot_unlabeled_images_random: plots unlabeled images at random
项目:Google-QuickDraw    作者:ankonzoid    | 项目源码 | 文件源码
def plot_unlabeled_images_random(image_list, n, title_str, ypixels, xpixels, seed, filename):
    random.seed(seed)
    index_sample = random.sample(range(len(image_list)), n)
    plt.figure(figsize=(2*n, 2))
    plt.suptitle(title_str)
    for i, ind in enumerate(index_sample):
        ax = plt.subplot(1, n, i + 1)
        plt.imshow(image_list[ind].reshape(ypixels, xpixels))
        plt.gray()
        ax.get_xaxis().set_visible(False); ax.get_yaxis().set_visible(False)
    if 1:
        pylab.savefig(filename, bbox_inches='tight')
    else:
        plt.show()

# plot_compare: given test images and their reconstruction, we plot them for visual comparison
项目:Google-QuickDraw    作者:ankonzoid    | 项目源码 | 文件源码
def plot_compare(x_test, decoded_imgs, filename):
    n = 10
    plt.figure(figsize=(2*n, 4))
    for i in range(n):
        # display original
        ax = plt.subplot(2, n, i + 1)
        plt.imshow(x_test[i].reshape(28, 28))
        plt.gray()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)

        # display reconstruction
        ax = plt.subplot(2, n, i + 1 + n)
        plt.imshow(decoded_imgs[i].reshape(28, 28))
        plt.gray()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)

    if 1:
        pylab.savefig(filename, bbox_inches='tight')
    else:
        plt.show()

# plot_img: plots greyscale image
项目:deep-learning-theano    作者:aidiary    | 项目源码 | 文件源码
def visualize_weights(W, outfile):
    # ?????????
    W = (W - np.min(W)) / (np.max(W) - np.min(W))
    W *= 255.0
    W = W.astype(np.int)

    pos = 1
    for i in range(100):
        plt.subplot(10, 10, pos)
        plt.subplots_adjust(wspace=0, hspace=0)
        plt.imshow(W[i].reshape(28, 28))
        plt.gray()
        plt.axis('off')
        pos += 1
    plt.show()
    plt.savefig(outfile)
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x, _ = mnist.test.next_batch(10)
    batch_p = sess.run(p, {x:batch_x})
    P = np.zeros((0, n_in))
    for i in range(10):
        P = np.concatenate([P, batch_x[i].reshape((1, n_in))], 0)
        for t in range(T):
            P = np.concatenate([P, batch_p[t][i].reshape((1, n_in))], 0)
    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (28, 28), (10, T+1)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    P = np.zeros((0, attunit.read_dim))
    for t in range(T):
        batch_att = sess.run(tf.nn.sigmoid(x_att[t]), {x:batch_x})
        P = np.concatenate([P, batch_att], 0)
    fig = plt.figure('attended')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (N, N), (10, T)))
    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x, _ = mnist.test.next_batch(100)
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p, {x:batch_x, is_train:False})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    p_gen = sess.run(p, {z:np.random.normal(size=(100, n_lat)), is_train:False})
    I_gen = batchmat_to_tileimg(p_gen, (height, width), (10, 10))
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(I_gen)
    fig.savefig(FLAGS.save_dir+'/generated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x = test_x[0:100]
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p, {x:batch_x})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    p_gen = sess.run(p, {z:np.random.normal(size=(100, n_lat))})
    I_gen = batchmat_to_tileimg(p_gen, (height, width), (10, 10))
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(I_gen)
    fig.savefig(FLAGS.save_dir+'/generated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x = test_x[0:100]
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p, {x:batch_x})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    p_gen = sess.run(p, {z:np.random.normal(size=(100, n_lat))})
    I_gen = batchmat_to_tileimg(p_gen, (height, width), (10, 10))
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(I_gen)
    fig.savefig(FLAGS.save_dir+'/generated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x = test_x[0:100]
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p, {x:batch_x})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    p_gen = sess.run(p, {z:np.random.normal(size=(100, n_lat))})
    I_gen = batchmat_to_tileimg(p_gen, (height, width), (10, 10))
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(I_gen)
    fig.savefig(FLAGS.save_dir+'/generated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x = test_x[0:100]
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p, {x:batch_x, is_training:False})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    p_gen = sess.run(p, {z:np.random.normal(size=(100, n_lat)), is_training:False})
    I_gen = batchmat_to_tileimg(p_gen, (height, width), (10, 10))
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(I_gen)
    fig.savefig(FLAGS.save_dir+'/generated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x, _ = mnist.test.next_batch(10)
    batch_p = sess.run(p, {x:batch_x})
    P = np.zeros((0, n_in))
    for i in range(10):
        P = np.concatenate([P, batch_x[i].reshape((1, n_in))], 0)
        for t in range(T):
            P = np.concatenate([P, batch_p[t][i].reshape((1, n_in))], 0)
    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (28, 28), (10, T+1)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    P = np.zeros((0, attunit.read_dim))
    for t in range(T):
        batch_att = sess.run(tf.nn.sigmoid(x_att[t]), {x:batch_x})
        P = np.concatenate([P, batch_att], 0)
    fig = plt.figure('attended')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (N, N), (10, T)))
    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x, _ = mnist.test.next_batch(10)
    batch_p = sess.run(p, {x:batch_x})
    P = np.zeros((0, n_in))
    for i in range(10):
        P = np.concatenate([P, batch_x[i].reshape((1, n_in))], 0)
        for t in range(T):
            P = np.concatenate([P, batch_p[t][i].reshape((1, n_in))], 0)
    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (28, 28), (10, T+1)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    P = np.zeros((0, attunit.read_dim))
    for t in range(T):
        batch_att = sess.run(tf.nn.sigmoid(x_att[t]), {x:batch_x})
        P = np.concatenate([P, batch_att], 0)
    fig = plt.figure('attended')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (N, N), (10, T)))
    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x, _ = mnist.test.next_batch(100)
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p, {x:batch_x, is_train:False})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    p_gen = sess.run(p, {z:np.random.normal(size=(100, n_lat)), is_train:False})
    I_gen = batchmat_to_tileimg(p_gen, (height, width), (10, 10))
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(I_gen)
    fig.savefig(FLAGS.save_dir+'/generated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x = test_x[0:100]
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p, {x:batch_x})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    p_gen = sess.run(p, {z:np.random.normal(size=(100, n_lat))})
    I_gen = batchmat_to_tileimg(p_gen, (height, width), (10, 10))
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(I_gen)
    fig.savefig(FLAGS.save_dir+'/generated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x, _ = mnist.test.next_batch(10)
    batch_p = sess.run(p, {x:batch_x})
    P = np.zeros((0, n_in))
    for i in range(10):
        P = np.concatenate([P, batch_x[i].reshape((1, n_in))], 0)
        for t in range(T):
            P = np.concatenate([P, batch_p[t][i].reshape((1, n_in))], 0)
    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (28, 28), (10, T+1)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    P = np.zeros((0, attunit.read_dim))
    for t in range(T):
        batch_att = sess.run(tf.nn.sigmoid(x_att[t]), {x:batch_x})
        P = np.concatenate([P, batch_att], 0)
    fig = plt.figure('attended')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (N, N), (10, T)))
    plt.show()
项目:NADE    作者:MarcCote    | 项目源码 | 文件源码
def plot_examples(nade, dataset, shape, name, rows=5, cols=10):    
    #Show some samples
    images = list()
    for row in xrange(rows):                     
        for i in xrange(cols):
            nade.setup_n_orderings(n=1)
            sample = dataset.sample_data(1)[0].T
            dens = nade.logdensity(sample)
            images.append((sample, dens))
    images.sort(key=lambda x: -x[1])

    plt.figure(figsize=(0.5*cols,0.5*rows), dpi=100)
    plt.gray()            
    for row in xrange(rows):                     
        for col in xrange(cols):
            i = row*cols+col
            sample, dens = images[i]
            plt.subplot(rows, cols, i+1)
            plot_sample(np.resize(sample, np.prod(shape)).reshape(shape), shape, origin="upper")
    plt.subplots_adjust(left=0.01, right=0.99, top=0.99, bottom=0.01, hspace=0.04, wspace=0.04)
    type_1_font()
    plt.savefig(os.path.join(DESTINATION_PATH, name))
项目:NADE    作者:MarcCote    | 项目源码 | 文件源码
def plot_samples(nade, shape, name, rows=5, cols=10):    
    #Show some samples
    images = list()
    for row in xrange(rows):                     
        for i in xrange(cols):
            nade.setup_n_orderings(n=1)
            sample = nade.sample(1)[:,0]
            dens = nade.logdensity(sample[:, np.newaxis])
            images.append((sample, dens))
    images.sort(key=lambda x: -x[1])

    plt.figure(figsize=(0.5*cols,0.5*rows), dpi=100)
    plt.gray()            
    for row in xrange(rows):                     
        for col in xrange(cols):
            i = row*cols+col
            sample, dens = images[i]
            plt.subplot(rows, cols, i+1)
            plot_sample(np.resize(sample, np.prod(shape)).reshape(shape), shape, origin="upper")
    plt.subplots_adjust(left=0.01, right=0.99, top=0.99, bottom=0.01, hspace=0.04, wspace=0.04)
    type_1_font()
    plt.savefig(os.path.join(DESTINATION_PATH, name))                
    #plt.show()
项目:NADE    作者:MarcCote    | 项目源码 | 文件源码
def inpaint_digits_(dataset, shape, model, n_examples = 5, delete_shape = (10,10), n_samples = 5, name = "inpaint_digits"):    
    #Load a few digits from the test dataset (as rows)
    data = dataset.sample_data(1000)[0]

    #data = data[[1,12,17,81,88,102],:]
    data = data[range(20,40),:]
    n_examples = data.shape[0]

    #Plot it all
    matplotlib.rcParams.update({'font.size': 8})
    plt.figure(figsize=(5,5), dpi=100)
    plt.gray()
    cols = 2 + n_samples
    for row in xrange(n_examples):
        # Original
        plt.subplot(n_examples, cols, row*cols+1)
        plot_sample(data[row,:], shape, origin="upper")        
    plt.subplots_adjust(left=0.01, right=0.99, top=0.95, bottom=0.01, hspace=0.40, wspace=0.04)
    plt.savefig(os.path.join(DESTINATION_PATH, "kk.pdf"))
项目:dsde-deep-learning    作者:broadinstitute    | 项目源码 | 文件源码
def plot_imgs_and_reconstructions(imgs, reconstructions, n=10, shape=(28,28)):
    plt.figure(figsize=(20, 4))
    for i in range(n):
        # display original
        ax = plt.subplot(2, n, i + 1)
        plt.imshow(imgs[i].reshape(shape))
        if len(shape) == 2:
            plt.gray()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)

        # display reconstruction
        ax = plt.subplot(2, n, i + 1 + n)
        plt.imshow(reconstructions[i].reshape(shape))
        if len(shape) == 2:
            plt.gray()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)
    plt.show()


# Back to the top!
项目:chainer-wasserstein-gan    作者:hvy    | 项目源码 | 文件源码
def save_ims(filename, ims, dpi=100):
    n, c, w, h = ims.shape
    x_plots = math.ceil(math.sqrt(n))
    y_plots = x_plots if n % x_plots == 0 else x_plots - 1
    plt.figure(figsize=(w*x_plots/dpi, h*y_plots/dpi), dpi=dpi)

    for i, im in enumerate(ims):
        plt.subplot(y_plots, x_plots, i+1)

        if c == 1:
            plt.imshow(im[0])
        else:
            plt.imshow(im.transpose((1, 2, 0)))

        plt.axis('off')
        plt.gca().set_xticks([])
        plt.gca().set_yticks([])
        plt.gray()
        plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0,
                            hspace=0)

    plt.savefig(filename, dpi=dpi*2, facecolor='black')
    plt.clf()
    plt.close()
项目:chainer-gan-improvements    作者:hvy    | 项目源码 | 文件源码
def save_ims(filename, ims, dpi=100):
    n, c, w, h = ims.shape
    x_plots = math.ceil(math.sqrt(n))
    y_plots = x_plots if n % x_plots == 0 else x_plots - 1
    plt.figure(figsize=(w*x_plots/dpi, h*y_plots/dpi), dpi=dpi)

    for i, im in enumerate(ims):
        plt.subplot(y_plots, x_plots, i+1)

        if c == 1:
            plt.imshow(im[0])
        else:
            raise NotImplementedError

        plt.axis('off')
        plt.gca().set_xticks([])
        plt.gca().set_yticks([])
        plt.gray()
        plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0,
                            hspace=0)

    plt.savefig(filename, dpi=dpi*2, facecolor='black')
    plt.clf()
    plt.close()
项目:EEDS-keras    作者:MarkPrecursor    | 项目源码 | 文件源码
def plot_figures(figures, nrows=1, ncols=1, titles=False):
    """Plot a dictionary of figures.
    Parameters
    ----------
    figures : <title, figure> dictionary
    ncols : number of columns of subplots wanted in the display
    nrows : number of rows of subplots wanted in the figure
    """
    fig, axeslist = plt.subplots(ncols=ncols, nrows=nrows)
    for ind, title in enumerate(sorted(figures.keys(), key=lambda s: int(s[3:]))):
        axeslist.ravel()[ind].imshow(figures[title], cmap=plt.gray())
        if titles:
            axeslist.ravel()[ind].set_title(title)

    for ind in range(nrows*ncols):
        axeslist.ravel()[ind].set_axis_off()

    if titles:
        plt.tight_layout()
    plt.show()
项目:jamespy_py3    作者:jskDr    | 项目源码 | 文件源码
def imshow(self):
        (_, _), (x_test_in, x_test) = self.Data
        x_test_in, x_test = update2(x_test_in, x_test)
        autoencoder = self.autoencoder
        decoded_imgs = autoencoder.predict(x_test_in)

        n = 10
        plt.figure(figsize=(20, 4))
        for i in range(n):
            # display original
            ax = plt.subplot(2, n, i + 1)
            plt.imshow(x_test[i].reshape(28, 28))
            plt.gray()
            ax.get_xaxis().set_visible(False)
            ax.get_yaxis().set_visible(False)

            # display reconstruction
            ax = plt.subplot(2, n, i + n + 1)
            plt.imshow(decoded_imgs[i].reshape(28, 28))
            plt.gray()
            ax.get_xaxis().set_visible(False)
            ax.get_yaxis().set_visible(False)
        plt.show()
项目:jamespy_py3    作者:jskDr    | 项目源码 | 文件源码
def imshow(self):
        (_, _), (x_test_in, x_test) = self.Data
        x_test_in, x_test = update2(x_test_in, x_test)
        autoencoder = self.autoencoder
        decoded_imgs = autoencoder.predict(x_test_in)

        n = 10
        plt.figure(figsize=(20, 4))
        for i in range(n):
            # display original
            ax = plt.subplot(2, n, i + 1)
            plt.imshow(x_test[i].reshape(28, 28))
            plt.gray()
            ax.get_xaxis().set_visible(False)
            ax.get_yaxis().set_visible(False)

            # display reconstruction
            ax = plt.subplot(2, n, i + n + 1)
            plt.imshow(decoded_imgs[i].reshape(28, 28))
            plt.gray()
            ax.get_xaxis().set_visible(False)
            ax.get_yaxis().set_visible(False)
        plt.show()
项目:human-rl    作者:gsastry    | 项目源码 | 文件源码
def display_example(x,i):
    # imsize=42*42
    # observation = x[2:imsize+2].reshape([42,42])
    # observation2 = x[imsize+2:].reshape([42,42])
    # print(observation.shape)
    # Plot the grid
    x = x.reshape(42,42)
    plt.imshow(x)
    plt.gray()
    #plt.show()
    plt.savefig('/tmp/catastrophe/frame_{}.png'.format(i))
项目:Google-QuickDraw    作者:ankonzoid    | 项目源码 | 文件源码
def plot_img(img, title_str, fignum):
    plt.plot(fignum), plt.imshow(img, cmap='gray')
    plt.title(title_str), plt.xticks([]), plt.yticks([])
    fignum += 1  # move onto next figure number
    plt.show()
    return fignum

# read image
项目:CycleGAN-Tensorflow-PyTorch-Simple    作者:LynnHo    | 项目源码 | 文件源码
def imshow(image):
    """ show a [-1.0, 1.0] image """
    plt.imshow(to_range(image), cmap=plt.gray())
项目:PyIntroduction    作者:tody411    | 项目源码 | 文件源码
def pltShowImageGray(image_file):
    image_gray = cv2.imread(image_file, 0)
    plt.title('image')
    plt.gray()
    plt.imshow(image_gray)
    plt.axis('off')
    plt.show()
项目:PyIntroduction    作者:tody411    | 项目源码 | 文件源码
def showImageGray(image_file):
    image_gray = cv2.imread(image_file, 0)
    plt.title('Gray')
    plt.gray()
    plt.imshow(image_gray)
    plt.axis('off')
    plt.show()


# HSV????????
项目:PyIntroduction    作者:tody411    | 项目源码 | 文件源码
def showImageHSV(image_file):
    image_bgr = cv2.imread(image_file)
    image_hsv = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2HSV)

    H = image_hsv[:, :, 0]
    S = image_hsv[:, :, 1]
    V = image_hsv[:, :, 2]

    plt.subplot(1, 3, 1)
    plt.title('Hue')
    plt.gray()
    plt.imshow(H)
    plt.axis('off')

    plt.subplot(1, 3, 2)
    plt.title('Saturation')
    plt.gray()
    plt.imshow(S)
    plt.axis('off')

    plt.subplot(1, 3, 3)
    plt.title('Value')
    plt.gray()
    plt.imshow(V)
    plt.axis('off')

    plt.show()


# Lab????????
项目:PyIntroduction    作者:tody411    | 项目源码 | 文件源码
def showImageLab(image_file):
    image_bgr = cv2.imread(image_file)
    image_Lab = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2LAB)

    L = image_Lab[:, :, 0]
    a = image_Lab[:, :, 1]
    b = image_Lab[:, :, 2]

    plt.subplot(1, 3, 1)
    plt.title('L')
    plt.gray()
    plt.imshow(L)
    plt.axis('off')

    plt.subplot(1, 3, 2)
    plt.title('a')
    plt.gray()
    plt.imshow(a)
    plt.axis('off')

    plt.subplot(1, 3, 3)
    plt.title('b')
    plt.gray()
    plt.imshow(b)
    plt.axis('off')

    plt.show()
项目:hyperas    作者:maxpumperla    | 项目源码 | 文件源码
def visualization_mnist(x_data,n=10):
    plt.figure(figsize=(20, 4))
    for i in range(n):
        # display digit
        ax = plt.subplot(1, n, i+1)
        plt.imshow(x_data[i].reshape(28, 28))
        plt.gray()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)
    plt.show()
项目:NICE    作者:aidangomez    | 项目源码 | 文件源码
def show_pane(top_digits, bottom_digits):
    """Displays two rows of digits on the screen.
    """

    all_digits = top_digits + bottom_digits
    fig, axes = plt.subplots(nrows = 2, ncols = int(len(all_digits)/2))
    for axis, digit in zip(axes.reshape(-1), all_digits):
        axis.imshow(digit, interpolation='nearest', cmap=plt.gray())
        axis.axis('off')
    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x = test_x[0:100]
    batch_p = sess.run(p, {x:batch_x})
    P = np.zeros((0, n_in))
    for i in range(10):
        P = np.concatenate([P, batch_x[i].reshape((1, n_in))], 0)
        for t in range(T):
            P = np.concatenate([P, batch_p[t][i].reshape((1, n_in))], 0)
    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (height, width), (10, T+1)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')
    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x = test_x[0:100]
    batch_p = sess.run(p, {x:batch_x})
    P = np.zeros((0, n_in))
    for i in range(10):
        P = np.concatenate([P, batch_x[i].reshape((1, n_in))], 0)
        for t in range(T):
            P = np.concatenate([P, batch_p[t][i].reshape((1, n_in))], 0)
    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (height, width), (10, T+1)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')
    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x, _ = mnist.test.next_batch(batch_size)
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p, {x:batch_x})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    batch_w = np.zeros((n_fac*n_fac, n_fac))
    for i in range(n_fac):
        batch_w[i*n_fac:(i+1)*n_fac, i] = 1.0
    batch_z = np.random.normal(size=(n_fac*n_fac, n_lat))
    p_gen = sess.run(p, {w:batch_w, z:batch_z})
    I_gen = batchmat_to_tileimg(p_gen, (height, width), (n_fac, n_fac))
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(I_gen)
    fig.savefig(FLAGS.save_dir+'/generated.png')

    fig = plt.figure('factor activation heatmap')
    hist = np.zeros((10, n_fac))
    for i in range(mnist.test.num_examples):
        batch_x, batch_y = mnist.test.next_batch(batch_size)
        batch_w = sess.run(w, {x:batch_x})
        for i in range(batch_size):
            hist[batch_y[i], batch_w[i] > 0] += 1
    sns.heatmap(hist)
    fig.savefig(FLAGS.save_dir+'/feature_activation.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x, _ = mnist.test.next_batch(batch_size)
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon, batch_w = sess.run([p, w], {x:batch_x})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    batch_w = np.zeros((n_fac*n_fac, n_fac))
    for i in range(n_fac):
        batch_w[i*n_fac:(i+1)*n_fac, i] = 1.0
    batch_z = np.random.normal(size=(n_fac*n_fac, n_lat))
    p_gen = sess.run(p, {w:batch_w, z:batch_z})
    I_gen = batchmat_to_tileimg(p_gen, (height, width), (n_fac, n_fac))
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(I_gen)
    fig.savefig(FLAGS.save_dir+'/generated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    np.random.shuffle(test_x)
    ind = ((test_y==3).nonzero())[0][0:10]
    batch_x = test_x[ind]
    batch_x_att, batch_x_hat, batch_pk, batch_p = \
            sess.run([x_att, x_hat, pk, p], {x:batch_x})

    A = np.zeros((0, N*N))
    for i in range(10):
        for k in range(K):
            A = np.concatenate([A, batch_x_att[k][i].reshape((1, N*N))], 0)
    fig = plt.figure('attended')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(A, (N, N), (10, K)))
    fig.savefig(FLAGS.save_dir+'/attended.png')

    P = np.zeros((0, n_in))
    for i in range(10):
        P = np.concatenate([P, batch_x[i].reshape((1, n_in))], 0)
        for k in range(K):
            P = np.concatenate([P, batch_pk[k][i].reshape((1, n_in))], 0)
        P = np.concatenate([P, batch_p[i].reshape((1, n_in))])
    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (height, width), (10, K+2)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x = test_x[0:100]
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p, {x:batch_x})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    batch_w = np.zeros((n_fac*n_fac, n_fac))
    for i in range(n_fac):
        batch_w[i*n_fac:(i+1)*n_fac, i] = 1.0
    batch_z = np.random.normal(size=(n_fac*n_fac, n_lat))
    p_gen = sess.run(p, {w:batch_w, z:batch_z})
    I_gen = batchmat_to_tileimg(p_gen, (height, width), (n_fac, n_fac))
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(I_gen)
    fig.savefig(FLAGS.save_dir+'/generated.png')

    """
    fig = plt.figure('factor activation heatmap')
    hist = np.zeros((10, n_fac))
    for i in range(len(test_x)):
        batch_x = test_x[i*batch_size:(i+1)*batch_size]
        batch_w = sess.run(w, {x:batch_x})
        for i in range(batch_size):
            hist[batch_y[i], batch_w[i] > 0] += 1
    sns.heatmap(hist)
    fig.savefig(FLAGS.save_dir+'/feature_activation.png')
    """

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    fig = plt.figure('generated')
    batch_z = np.random.uniform(-1, 1, [100, 100])
    batch_y = np.zeros((100, 10))
    for i in range(10):
        batch_y[i*10:(i+1)*10,i] = i
    gen = sess.run(fake, {z:batch_z, y:batch_y, is_train:False})
    plt.gray()
    plt.axis('off')
    plt.imshow(batchimg_to_tileimg(gen, (10, 10)))
    fig.savefig(FLAGS.save_dir+'/genereated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x, batch_y = mnist.test.next_batch(100)

    """
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p_x, {x:batch_x, y:batch_y})
    plt.imshow(batchmat_to_tileimg(p_recon, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')
    """

    batch_z = np.random.normal(size=(100, 50))
    batch_y = np.zeros((100, 10))
    for i in range(10):
        batch_y[i*10:(i+1)*10, i] = 1.0
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    p_gen = sess.run(p_x, {z:batch_z, y:batch_y, is_train:False})
    plt.imshow(batchmat_to_tileimg(p_gen, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/generated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    fig = plt.figure('generated')
    gen = sess.run(fake, {z:np.random.normal(size=(100, 128)), is_train:False})
    plt.gray()
    plt.axis('off')
    plt.imshow(batchimg_to_tileimg(gen, (10, 10)))
    fig.savefig(FLAGS.save_dir+'/genereated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    fig = plt.figure('generated')
    batch_z = np.random.normal(size=(100, 128))
    batch_y = np.zeros((100, 10))
    for i in range(10):
        batch_y[10*i:10*(i+1), i] = i
    gen = sess.run(fake, {z:batch_z, y:batch_y, is_train:False})
    plt.gray()
    plt.axis('off')
    plt.imshow(batchimg_to_tileimg(gen, (10, 10)))
    fig.savefig(FLAGS.save_dir+'/genereated.png')

    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x = test_x[0:100]
    batch_p = sess.run(p, {x:batch_x})
    P = np.zeros((0, n_in))
    for i in range(10):
        P = np.concatenate([P, batch_x[i].reshape((1, n_in))], 0)
        for t in range(T):
            P = np.concatenate([P, batch_p[t][i].reshape((1, n_in))], 0)
    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (height, width), (10, T+1)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')
    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')
    batch_x = test_x[0:100]
    batch_p = sess.run(p, {x:batch_x})
    P = np.zeros((0, n_in))
    for i in range(10):
        P = np.concatenate([P, batch_x[i].reshape((1, n_in))], 0)
        for t in range(T):
            P = np.concatenate([P, batch_p[t][i].reshape((1, n_in))], 0)
    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(P, (height, width), (10, T+1)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')
    plt.show()
项目:tf_practice    作者:juho-lee    | 项目源码 | 文件源码
def test():
    saver.restore(sess, FLAGS.save_dir+'/model.ckpt')

    test_acc = 0.
    for i in range(n_test_batches):
        batch_x, batch_y = mnist.test.next_batch(batch_size)
        batch_acc = sess.run(accuracy, {x:batch_x, y:batch_y})
        test_acc += batch_acc
    test_acc /= n_test_batches
    print 'test acc %f\n' % (test_acc)

    batch_x, batch_y = mnist.test.next_batch(100)
    fig = plt.figure('original')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchmat_to_tileimg(batch_x, (height, width), (10, 10)))
    fig.savefig(FLAGS.save_dir+'/original.png')

    fig = plt.figure('reconstructed')
    plt.gray()
    plt.axis('off')
    p_recon = sess.run(p, {x:batch_x})
    plt.imshow(batchimg_to_tileimg(p_recon, (10, 10)))
    fig.savefig(FLAGS.save_dir+'/reconstructed.png')

    p_gen = sess.run(p, {z:np.random.normal(size=(100, n_lat))})
    fig = plt.figure('generated')
    plt.gray()
    plt.axis('off')
    plt.imshow(batchimg_to_tileimg(p_gen, (10, 10)))
    fig.savefig(FLAGS.save_dir+'/generated.png')

    plt.show()
项目:Bicycle-Model    作者:caiofis    | 项目源码 | 文件源码
def show(self):
        """Plot the image as a b&w plot"""
        plt.imshow(self.pixels)#, interpolation='nearest')
        plt.axis([0,self.pixels[0].size,0,self.pixels.size/self.pixels[0].size])
        plt.gray()
        #plt.draw()
项目:dsde-deep-learning    作者:broadinstitute    | 项目源码 | 文件源码
def plot_templates(templates, epoch):
    n = 10
    templates = templates.reshape((28,28,n))
    plt.figure(figsize=(16, 8))
    for i in range(n):
        ax = plt.subplot(2, 5, i+1)     
        plt.imshow(templates[:, :, i])
        plt.gray()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)

    plot_name = "./frames/mnist/regression/templates_"+str(epoch)+".png"
    if not os.path.exists(os.path.dirname(plot_name)):
        os.makedirs(os.path.dirname(plot_name))     
    plt.savefig(plot_name)
项目:soinn    作者:fukatani    | 项目源码 | 文件源码
def draw_digit(data, n, row, col, title):
    import matplotlib.pyplot as plt
    size = 28
    plt.subplot(row, col, n)
    Z = data.reshape(size,size)   # convert from vector to 28x28 matrix
    Z = Z[::-1,:]                 # flip vertical
    plt.xlim(0,28)
    plt.ylim(0,28)
    plt.pcolor(Z)
    plt.title("title=%s"%(title), size=8)
    plt.gray()
    plt.tick_params(labelbottom="off")
    plt.tick_params(labelleft="off")
项目:DeepPicker-python    作者:nejyeah    | 项目源码 | 文件源码
def plot_circle_in_micrograph(micrograph_2d, coordinate, particle_size, filename, color = 'white'):
    """plot the particle circle in micrograph image 

    Based on the coordinate of particle, plot circles of the particles in the micrograph.
    And save the ploted image in filename.

    Args:
        micrograph_2d: numpy.array,it is a 2D numpy array.
        coordinate: list, it is a 2D list, the shape is (num_particle, 2).
        particle_size: int, the value of the particle size
        filename: the filename of the image to be save.
        color: define the color of the circle

    Raises:
        pass
    """
    micrograph_2d = micrograph_2d.reshape(micrograph_2d.shape[0], micrograph_2d.shape[1])
    fig = plt.figure()
    ax = fig.add_subplot(111)
    plt.axis('off')
    plt.gray()
    plt.imshow(micrograph_2d)
    radius = particle_size/2
    i = 0 
    while True: 
        if i >= len(coordinate):
            break
        coordinate_x = coordinate[i][0]
        coordinate_y = coordinate[i][1]
        cir1 = Circle(xy = (coordinate_x, coordinate_y), radius = radius, alpha = 0.5, color = color, fill = False)
        ax.add_patch(cir1)
        # extract the particles
        i = i + 1
    plt.savefig(filename)