def add_particles(self,
                      particle_position,
                      radius,
                      radius_scale=1.0,
                      color=(1, 1, 1),
                      color_by='',
                      alpha=1.0,
                      alpha_by='',
                      kernel=1.0):

        if len(color_by) == len(particle_position):
            if np.max(color_by) > 1.0:
                color_by /= np.max(color_by)
            import matplotlib.cm as cm
            #color = cm.winter_r(color_by)
            color = cm.GnBu(color_by)
            color = color[:, 0:3]

        if len(alpha_by) == len(particle_position):
            if np.max(alpha_by) > 1.0:
                alpha_by /= np.max(alpha_by)
            alpha = alpha_by

        self.particles.append({
            'pos': particle_position,
            'color': color,
            'alpha': alpha,
            'radius': radius,
            'radius_scale': radius_scale,
            'kernel': kernel
        })
Exemple #2
0
def get_cmaps_biasCNN():
    """ 
  Create color maps
  """

    nsteps = 8
    colors_all_1 = np.moveaxis(
        np.expand_dims(cm.Greys(np.linspace(0, 1, nsteps)), axis=2), [0, 1, 2],
        [0, 2, 1])
    colors_all_2 = np.moveaxis(
        np.expand_dims(cm.GnBu(np.linspace(0, 1, nsteps)), axis=2), [0, 1, 2],
        [0, 2, 1])
    colors_all_3 = np.moveaxis(
        np.expand_dims(cm.YlGn(np.linspace(0, 1, nsteps)), axis=2), [0, 1, 2],
        [0, 2, 1])
    colors_all_4 = np.moveaxis(
        np.expand_dims(cm.OrRd(np.linspace(0, 1, nsteps)), axis=2), [0, 1, 2],
        [0, 2, 1])
    colors_all = np.concatenate((colors_all_1[np.arange(2, nsteps, 1), :, :],
                                 colors_all_2[np.arange(2, nsteps, 1), :, :],
                                 colors_all_3[np.arange(2, nsteps, 1), :, :],
                                 colors_all_4[np.arange(2, nsteps, 1), :, :],
                                 colors_all_2[np.arange(2, nsteps, 1), :, :]),
                                axis=1)

    int_inds = [3, 3, 3, 3]
    colors_main = np.asarray(
        [colors_all[int_inds[ii], ii, :] for ii in range(np.size(int_inds))])
    colors_main = np.concatenate((colors_main, colors_all[5, 1:2, :]), axis=0)
    # plot the color map
    #plt.figure();plt.imshow(np.expand_dims(colors_main,axis=0))
    colors_sf = np.moveaxis(
        np.expand_dims(cm.GnBu(np.linspace(0, 1, 8)), axis=2), [0, 1, 2],
        [0, 2, 1])
    colors_sf = colors_sf[np.arange(2, 8, 1), :, :]

    return colors_main, colors_sf
Exemple #3
0
def plot_cube(cube, angle=320):
    '''cube must be 3d
	'''
    cube = normalize(cube)
    cube = np.expand_dims(cube, axis=-1)  #28x28x1
    facecolors = cm.GnBu(cube)  #28x28x4
    filled = np.ones(cube.shape)  #28x28x1

    x, y, z = np.indices(np.array(cube.shape) + 1)  #29x29x2 for each axis

    fig = plt.figure(figsize=[6, 6])
    ax = fig.gca(projection='3d')
    ax.view_init(30, angle)
    ax.set_axis_off()
    ax.set_box_aspect((cube.shape[0], cube.shape[1], 20))

    ax.voxels(x, y, z, filled=filled, facecolors=facecolors, linewidth=0.0001)

    plt.show()
Exemple #4
0
    def Visual3D(self, draw_edge=True):
        fig = plt.figure(figsize=[10, 10])
        ax = fig.gca(projection='3d')
        pos = self.pos
        x = pos.T[0]
        y = pos.T[1]
        z = pos.T[2]
        ax.scatter(x, y, z, c='r')

        edge = set()
        for i in range(self.n):
            for j in range(self.n):
                if (i != j and self.adjacence[i, j] > 1.e-5):
                    x1, x2 = pos[i][0], pos[j][0]
                    y1, y2 = pos[i][1], pos[j][1]
                    z1, z2 = pos[i][2], pos[j][2]
                    if (x1 > x2):
                        x1, x2 = x2, x1
                        y1, y2 = y2, y1
                        z1, z2 = z2, z1
                    edge.add(((x1, x2), (y1, y2), (z1, z2)))
        edge = list(edge)
        if (draw_edge):
            for i in range(len(edge)):
                ax.plot(*edge[i])
        plt.show()

        #Projection2D
        edge = set()
        fig = plt.figure(figsize=[10, 10])
        for i in range(self.n):
            for j in range(self.n):
                if (i != j and self.adjacence[i, j] > 1.e-5):
                    x1, x2 = pos[i][0], pos[j][0]
                    y1, y2 = pos[i][1], pos[j][1]

                    if (x1 > x2):
                        x1, x2 = x2, x1
                        y1, y2 = y2, y1
                    edge.add(((x1, x2), (y1, y2)))
        edge = list(edge)
        if (draw_edge):
            for i in range(len(edge)):
                plt.plot(*edge[i], color='black', linewidth=0.3)

        point_c = pos[:, 2] / np.max(pos[:, 2])
        colors = cm.rainbow(point_c)
        plt.scatter(x, y, color=colors)
        plt.show()
        #PCA Verion
        fig = plt.figure(figsize=[10, 10])
        edge = set()
        pca = PCA(2)
        pca.fit(self.pos)
        pos = pca.transform(self.pos)
        for i in range(self.n):
            for j in range(self.n):
                if (i != j and self.adjacence[i, j] > 1.e-5):
                    x1, x2 = pos[i][0], pos[j][0]
                    y1, y2 = pos[i][1], pos[j][1]

                    if (x1 > x2):
                        x1, x2 = x2, x1
                        y1, y2 = y2, y1
                    edge.add(((x1, x2), (y1, y2)))
        edge = list(edge)
        for i in range(len(edge)):
            plt.plot(*edge[i], color='black', linewidth=0.3)
        colors = cm.GnBu(point_c)
        plt.scatter(pos.T[0], pos.T[1], color=colors)
        plt.show()
cmap = cm.GnBu

bounds = np.linspace(0, 40, 41)
norm = colors.BoundaryNorm(bounds, cmap.N)

#bounds = np.linspace(0,120,21)
#norm = colors.BoundaryNorm(bounds, ncolors=256)
#print norm(100)

#sys.exit()

for key, value in patches.iteritems():
    print key + " " + str(color[key])
    ax.add_collection(
        PatchCollection(value,
                        facecolor=cm.GnBu(norm(color[key])),
                        cmap=cm.GnBu,
                        edgecolor='k',
                        linewidth=1.,
                        zorder=2))

#    ax.add_collection(PatchCollection(value, facecolors=color[key], cmap=cm.GnBu, edgecolor='k',
#        linewidth=1., zorder=2, norm=norm))

### Plot colorbar
#set room for colorbar
fig.subplots_adjust(right=0.85)

axcb = fig.add_axes([0.87, 0.15, 0.03, 0.7])

cb = mpl.colorbar.ColorbarBase(axcb,
Exemple #6
0
import csv
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdate
import time
import matplotlib.colors as colors_fun
import matplotlib.cm as cm
import plotly.plotly as py
import plotly.graph_objs as go
import pdb

file = open('homeless_by_county.csv', 'rt')
reader = csv.reader(file)
data = [x for x in reader]
county = [x[0] for x in data]
number = [x[1] for x in data]

colors = cm.GnBu(np.linspace(1, 0, len(number)) )
colors = [colors_fun.rgb2hex(color) for color in colors]	

trace = go.Pie(labels=county, values=number,
               hoverinfo='label+percent', textinfo='value', 
               textfont=dict(size=20),
               marker=dict(colors=colors, 
                           line=dict(color='#000000', width=0.5)))

py.iplot([trace], filename='Homeless-by-county')