示例#1
0
def plot_color_gradients(cmap_category, cmap_list):
    fig, axes = plt.subplots(nrows=nrows, ncols=2)
    fig.subplots_adjust(top=0.95,
                        bottom=0.01,
                        left=0.2,
                        right=0.99,
                        wspace=0.05)
    fig.suptitle(cmap_category + ' colormaps', fontsize=14, y=1.0, x=0.6)

    for ax, name in zip(axes, cmap_list):

        # Get rgb values for colormap
        rgb = cm.get_cmap(plt.get_cmap(name))(x)[np.newaxis, :, :3]

        # Get colormap in CIE LAB. We want the L here.
        lab = color.rgb2lab(rgb)
        L = lab[0, :, 0]
        L = np.float32(np.vstack((L, L, L)))

        ax[0].imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
        ax[1].imshow(L, aspect='auto', cmap='binary_r', vmin=0., vmax=100.)
        pos = list(ax[0].get_position().bounds)
        x_text = pos[0] - 0.01
        y_text = pos[1] + pos[3] / 2.
        fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)

    # Turn off *all* ticks & spines, not just the ones with colormaps.
    for ax in axes:
        ax[0].set_axis_off()
        ax[1].set_axis_off()
    plt.show()
示例#2
0
def posterize(data, colors):
    # convert data to Lab color space
    data_lab = colorconv.rgb2lab(data)
    # Now take the norm of each vector in each matrix
    distances = [color_distance(data_lab, c) for c in colors]
    # Find the shortest norm to find the closest color
    return numpy.argmin(distances, axis=0)
示例#3
0
def plot_color_gradients(cmap_category, cmap_list):
    nrows = len(cmap_list)
    fig, axes = plt.subplots(nrows=nrows, ncols=2)
    fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99,
                        wspace=0.05)
    fig.suptitle(cmap_category + ' colormaps', fontsize=14, y=1.0, x=0.6)

    for ax, name in zip(axes, cmap_list):

        # Get rgb values for colormap
        rgb = cm.get_cmap(plt.get_cmap(name))(x)[np.newaxis,:,:3]

        # Get colormap in CIE LAB. We want the L here.
        lab = color.rgb2lab(rgb)
        L = lab[0,:,0]
        L = np.float32(np.vstack((L, L, L)))

        ax[0].imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
        ax[1].imshow(L, aspect='auto', cmap='binary_r', vmin=0., vmax=100.)
        pos = list(ax[0].get_position().bounds)
        x_text = pos[0] - 0.01
        y_text = pos[1] + pos[3]/2.
        fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)

    # Turn off *all* ticks & spines, not just the ones with colormaps.
    for ax in axes:
        ax[0].set_axis_off()
        ax[1].set_axis_off()
    plt.show()
示例#4
0
def posterize(data, colors) :
    # convert data to Lab color space
    data_lab = colorconv.rgb2lab(data)
    # Now take the norm of each vector in each matrix
    distances = [color_distance(data_lab, c) for c in colors]
    # Find the shortest norm to find the closest color
    return numpy.argmin(distances, axis=0)
示例#5
0
    fig = plt.figure(figsize=(11.5,4*nsubplots))

    for i, subplot in enumerate(xrange(nsubplots)):

        locs = [] # locations for text labels

        ax = fig.add_subplot(nsubplots, 1, i+1)
        # pdb.set_trace()

        for j, cmap in enumerate(cmap_list[i*dsub:(i+1)*dsub]):

            # Get rgb values for colormap
            rgb = cm.get_cmap(cmap)(x)[np.newaxis,:,:3]

            # Get colormap in CIE LAB. We want the L here.
            lab = color.rgb2lab(rgb)

            # Plot colormap L values
            # Do separately for each category so each plot can be pretty
            # to make scatter markers change color along plot: http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable
            if cmap_category=='Sequential':
                dc = 0.6 # spacing between colormaps
                ax.scatter(x+j*dc, lab[0,::-1,0], c=x, cmap=cmap + '_r', s=300, linewidths=0.)
                if i==2:
                    ax.axis([-0.1,4.1,0,100])
                else:
                    ax.axis([-0.1,4.7,0,100])
                locs.append(x[-1]+j*dc) # store locations for colormap labels

            elif cmap_category=='Sequential2':
                dc = 1.15
示例#6
0
mpl.rcParams['mathtext.tt'] = 'monospace'
mpl.rcParams['mathtext.it'] = 'sans:italic'
mpl.rcParams['mathtext.bf'] = 'sans:bold'
mpl.rcParams['mathtext.sf'] = 'sans'
mpl.rcParams['mathtext.fallback_to_cm'] = 'True'


### Red, original Albers plot

nrows = 5

# Start with red
red = np.array([np.hstack([np.ones((nrows,1)), np.zeros((nrows,2))])])

# Get basic red in LAB
lab_add = color.rgb2lab(red)
lab_geometric = lab_add.copy()

# Alter successive rows with more black
k = 1
for i in range(red.shape[1]):
    # more blackness is closer to 0 than one, and in first column of LAB
    lab_add[0,i,0] = lab_add[0,i,0] - 10*i
    print(i,k)
    if i != 0:
        lab_geometric[0,i,0] = lab_geometric[0,i,0] - 10*k
        k *= 2

# Change LAB back to RGB for plotting
rgb_add = red.copy() # only change red values
temp = color.lab2rgb(lab_add)
示例#7
0
mpl.rcParams['mathtext.rm'] = 'sans'
mpl.rcParams['mathtext.tt'] = 'monospace'
mpl.rcParams['mathtext.it'] = 'sans:italic'
mpl.rcParams['mathtext.bf'] = 'sans:bold'
mpl.rcParams['mathtext.sf'] = 'sans'
mpl.rcParams['mathtext.fallback_to_cm'] = 'True'

### Red, original Albers plot

nrows = 5

# Start with red
red = np.array([np.hstack([np.ones((nrows, 1)), np.zeros((nrows, 2))])])

# Get basic red in LAB
lab_add = color.rgb2lab(red)
lab_geometric = lab_add.copy()

# Alter successive rows with more black
k = 1
for i in range(red.shape[1]):
    # more blackness is closer to 0 than one, and in first column of LAB
    lab_add[0, i, 0] = lab_add[0, i, 0] - 10 * i
    if i != 0:
        lab_geometric[0, i, 0] = lab_geometric[0, i, 0] - 10 * k
        k *= 2

# Change LAB back to RGB for plotting
rgb_add = red.copy()  # only change red values
temp = color.lab2rgb(lab_add)
rgb_add[0, :, 0] = temp[0, :, 0]
示例#8
0
    fig = plt.figure(figsize=(7, 2.6 * nsubplots))

    for i, subplot in enumerate(range(nsubplots)):

        locs = []  # locations for text labels

        ax = fig.add_subplot(nsubplots, 1, i + 1)

        for j, cmap in enumerate(cmap_list[i * dsub:(i + 1) * dsub]):

            # Get rgb values for colormap
            rgb = cm.get_cmap(cmap)(x)[np.newaxis, :, :3]

            # Get colormap in CIE LAB. We want the L here.
            lab = color.rgb2lab(rgb)

            # Plot colormap L values
            # Do separately for each category so each plot can be pretty
            # to make scatter markers change color along plot:
            # http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable
            if cmap_category == 'Perceptually Uniform Sequential':
                dc = 1.15  # spacing between colormaps
                ax.scatter(x + j * dc,
                           lab[0, ::-1, 0],
                           c=x,
                           cmap=cmap,
                           s=300,
                           linewidths=0.)
                if i == 2:
                    ax.axis([-0.1, 4.1, 0, 100])
示例#9
0
def color_to_lab(c):
    l = colorconv.rgb2lab(
        numpy.reshape(numpy.array(c, dtype=numpy.uint8), (1, 1, 3)))
    return numpy.reshape(l, (3))
示例#10
0
def color_to_lab(c) :
    l = colorconv.rgb2lab(numpy.reshape(numpy.array(c, dtype=numpy.uint8),(1,1,3)))
    return numpy.reshape(l,(3))