Пример #1
0
def pShow(p, maze):

    # visualize probability distribution

    # ==================================
    # p: probability distribution with shape (80,1)
    # input should be raw probability distribution [pn] (sum of all terms equals to 1), instead of [-np.log(pn)]
    # blue color represents walls, white/red squares are valid position, the larger value on red, the larger probability it has
    # ==================================

    iW = 1 - maze.world
    colormap = np.zeros((maze.worldShape))
    p_reshape = np.reshape(p, maze.worldShape)
    valid = np.multiply(p_reshape, iW)
    max_p = np.max(valid)
    if max_p > 0:
        nonzero = np.nonzero(p_reshape > 0)
        for i in range(nonzero[0].shape[0]):
            colormap[7 - nonzero[0][i]][
                nonzero[1][i]] = p_reshape[nonzero[0][i]][nonzero[1][i]] * (
                    1.0 / max_p
                )  # map largest p to 1, make sure empty space is white
    nonzero = np.nonzero(maze.world == 1)
    for i in range(nonzero[0].shape[0]):
        colormap[7 - nonzero[0][i]][nonzero[1][i]] = -1
    fig, ax = plt.subplots(1)
    ppl.pcolormesh(fig, ax, colormap)
    plt.show()
Пример #2
0
def draw_real_facebb_res():
    from prettyplotlib import brewer2mpl
    from matplotlib.colors import LogNorm
    red_purple = brewer2mpl.get_map('RdPu', 'Sequential', 9).mpl_colormap
    names = [
        'TREES', 'CFAN', 'RCPR', 'IFA', 'CFSS', 'SDM', 'LBF', 'TCDCN', 'CCNF',
        'GNDPM', 'DRMF', 'CFSS'
    ]
    bbsname = ['IBUG', 'V&J', 'HOG+SVM', 'HeadHunter']
    mat = np.loadtxt('expdata/fig_confmatrix.txt')
    fig, ax = plt.subplots(1)
    ppl.pcolormesh(fig, ax, mat.T, xticklabels=names, yticklabels=bbsname)
    bestbbpairs = [2, 1, 1, 0, 0, 0, 2, 0, 0, 1, 0]
    for k in range(len(bbsname)):
        for k2 in range(11):
            if bestbbpairs[k2] == k:
                ax.annotate(('%1.5f' % mat[k2][k])[:6],
                            xy=(k2 + 0.5, k + 0.5),
                            bbox=dict(boxstyle="round", fc="cyan", alpha=0.8),
                            horizontalalignment='center',
                            verticalalignment='center')
            else:
                ax.annotate(('%1.5f' % mat[k2][k])[:6],
                            xy=(k2 + 0.5, k + 0.5),
                            horizontalalignment='center',
                            verticalalignment='center')
    plt.xlim((0, 11))
Пример #3
0
def heatmap(file, theta_inc, theta_max):
    #env.log("Start ploting heatmap for {} ...".format(file), flush=True)
    if os.path.getsize(file) == 0:
        hinton('{}.png'.format(file))
        return
    lods = []
    with open(file, 'r') as f:
        for line in f.readlines():
            theta,lod = line.split()[-2:]
            if float(theta) >= theta_max:
                continue
            lods.append(lod)
        if max(lods) == min(lods):
            #env.log('Max equals Min for [{}], No real heatmap will be generated.'.format(file))
            hinton('{}.png'.format(file))
            return
        Num=int(round(theta_max/theta_inc))
        lods = np.array(map(float,lods)).reshape((-1,Num))
        chrID = re.search(r'\.chr([0-9XY]+)\.', file).group(1)
        fig, ax = plt.subplots(1)
        ax.set_title('Chromosome {}'.format(chrID))
        ppl.pcolormesh(fig,ax,lods.transpose(),
                       xticklabels=[''] * len(lods),
                       yticklabels=np.round(np.array(range(Num)) * theta_inc,2).tolist(),
                       cmap=brewer2mpl.get_map('Blues', 'Sequential', 9).mpl_colormap)
        fig.savefig('{}.png'.format(file))
def test_pcolormesh_lognorm():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    x = np.abs(np.random.randn(10, 10))
    ppl.pcolormesh(fig, ax, x, norm=LogNorm(vmin=x.min().min(), vmax=x.max().max()))
Пример #5
0
    def generate_daytimeheatmap(self):

        bins = np.zeros(shape=(7, 24))

        min_activated = self.interactions.data_frame.activated_ts.idxmin()
        start_day = self.interactions.data_frame.activated_ts[min_activated].date()
        max_activated = self.interactions.data_frame.deactivated_ts.idxmax()
        end_day = self.interactions.data_frame.deactivated_ts[max_activated].date()

        offset_end_of_hour = Hour() - Milli()

        ylabels = []

        for (idx, day) in enumerate(pd.date_range(start=start_day, end=end_day, freq='D')):
            for hour in range(24):
                start_of_hour = day + Hour()*hour
                end_of_hour = start_of_hour + offset_end_of_hour
                # generate ylabels, eg. 00:00 - 00:59
                if idx == 0:
                    ylabels.insert(0,"%s - %s" % (start_of_hour.strftime("%H:%M"), end_of_hour.strftime("%H:%M")))

                num_interactions = self.interactions.count_interactions_between(start_of_hour, end_of_hour)
                wday = day.weekday()
                bins[wday][23-hour] += num_interactions

        fig, ax = self._subplots(figsize=(8,8))

        xlabels = 'Mon Tue Wen Thur Fri Sat Sun'.split()

        # bins = bins[~np.all(bins == 0, axis=1)]

        ppl.pcolormesh(fig, ax, bins.T, xticklabels=xlabels, yticklabels=ylabels)

        fig.savefig(os.path.join(self.output_folder, self.FILENAME), bbox_inches='tight', dpi=300)
Пример #6
0
def test_pcolormesh_negative():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(fig, ax, -np.random.uniform(size=(10, 10)),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:])
Пример #7
0
def test_pcolormesh_labels():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(fig, ax, np.random.randn(10, 10),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:])
Пример #8
0
 def plot_score(mat):
     ppl.pcolormesh(
         np.flipud(mat.values),
         xticklabels=mat.columns.tolist(),
         yticklabels=mat.index.tolist()[::-1],
         # , norm=mpl.colors.LogNorm(vmin=mat.values.min(),
         #                           vmax=mat.values.max())
         cmap=mpl.cm.YlOrBr)
def test_pcolormesh_positive():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(
        fig, ax, np.random.uniform(size=(10, 10)), xticklabels=string.uppercase[:10], yticklabels=string.lowercase[-10:]
    )
Пример #10
0
def test_pcolormesh_labels():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(
        fig, ax, np.random.randn(10, 10), xticklabels=string.uppercase[:10], yticklabels=string.lowercase[-10:]
    )
Пример #11
0
def test_pcolormesh_other_cmap():
    purple_green = brewer2mpl.get_map('PRGn', 'diverging', 11).mpl_colormap

    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(fig, ax, np.random.randn(10, 10), cmap=purple_green)
Пример #12
0
def test_pcolormesh_positive_other_cmap():
    red_purple = brewer2mpl.get_map('RdPu', 'sequential', 8).mpl_colormap
    np.random.seed(10)

    ppl.pcolormesh(np.random.uniform(size=(10, 10)),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:],
                   cmap=red_purple)
Пример #13
0
def test_pcolormesh_positive_other_cmap():
    red_purple = brewer2mpl.get_map('RdPu', 'sequential', 8).mpl_colormap
    np.random.seed(10)

    ppl.pcolormesh(np.random.uniform(size=(10, 10)),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:],
                   cmap=red_purple)
Пример #14
0
def plot_hist_prettyplotlib(band, type, data):
    dim = data.shape
    print 'data dim ', dim
    fig, ax = ppl.subplots(1)
    ppl.pcolormesh(fig, ax, data, vmin=-0.0016, vmax=0.0016)
    plt.title('%s: band %s' % (type, band))
    plt.xlabel('buckets')
    plt.ylabel('time')
    fig.savefig("%s-histogram-%s.png" % (type, band))
Пример #15
0
 def plot_helper(li, ti, p):
     fig, ax = plt.subplots(1)
     if li % 2:
         title = "biases" + ti
         ppl.bar(ax, numpy.arange(p.shape[0]), p)
     else:
         title = "weights" + ti
         ppl.pcolormesh(fig, ax, p)
     plt.title(title)
     plt.savefig(title + ".png")
     #ppl.show()
     plt.close()
Пример #16
0
 def plot_helper(li, ti, p):
     fig, ax = plt.subplots(1)
     if li % 2:
         title = "biases" + ti
         ppl.bar(ax, numpy.arange(p.shape[0]), p)
     else:
         title = "weights" + ti
         ppl.pcolormesh(fig, ax, p)
     plt.title(title)
     plt.savefig(title + ".png")
     #ppl.show()
     plt.close()
Пример #17
0
def ppl_cmap ():
    '''
    This function is designed for creating a simple default prettyplotlib
    color map for reproducing a color map created in part 2.

    Note:
        This function requires "prettyplotlib" library.
    '''
    ax = fig.add_subplot(1,3,3)
    np.random.seed(10)
    ppl.pcolormesh(fig, ax, np.random.randn(10,10))
    ax.set_title('Color map with\nprettyplotlib default pcolormesh',fontsize=11.5)
Пример #18
0
def heatmap(input_data, parameters, output):
    data = []
    with open(input_data) as f:
        f_csv = csv.reader(f)
        for row in f_csv:
            data.append([float(item) for item in row])
    f.close()

    data = array(data)
    fig, ax = plt.subplots(1)
    ppl.pcolormesh(fig, ax, data)
    ax.set_title(parameters['title'])
    fig.savefig(output, format='svg')
Пример #19
0
    def draw_color_mesh(self):
        '''
        Draws a heatmap of pairs of heroes which co-occur
        in the winning and in the losing teams, useful to
        visualize the relationship between strong pairs of
        heroes which lead to victories vs. weak pairs of
        heroes which don't have much synergy
        '''
        red_yellow = brewer2mpl.get_map('YlGnBu', 'Sequential', 9).mpl_colormap

        fig, ax = plt.subplots(1, figsize=(13, 10))
        ax.set_xlim([0, self.c])
        ax.set_ylim([0, self.c])

        mesh = np.zeros((self.c, self.c), dtype=float)
        for i in range(0, self.c):
            for j in range(0, self.c):
                if i >= j:
                    # Same hero cannot be picked twice
                    continue

                if (i, j) in self.dwstat:
                    if self.ddstat[(i, j)] != 0:
                        k = round(
                            self.dwstat[(i, j)] /
                            float(self.ddstat[(i, j)] + self.dwstat[(i, j)]),
                            2)
                        mesh[i][j] = k
                        mesh[j][i] = k

        # *************************************************************** #
        # Code to calculate the max ratios in the heatmap
        # and obtain their hero indices too
        # Get the indices for the largest `num_largest` values.
        num_largest = 8
        indices = mesh.argpartition(mesh.size - num_largest,
                                    axis=None)[-num_largest:]
        x, y = np.unravel_index(indices, mesh.shape)
        print "full:"
        print "x =", x
        print "y =", y
        print "Largest values:", mesh[x, y]
        # print "Compare to:    ", np.sort(mesh, axis=None)[-num_largest:]
        # **************************************************************** #

        ppl.pcolormesh(fig, ax, mesh, cmap=red_yellow)
        fig.savefig('../Figures/HeatMap-heroPairs.png')
        plt.show()
        plt.clf()
def plot_method_pairs_and_matrix(case_studies,fileappend=''):
    case_cov=np.cov(case_studies.transpose())
    case_corr=np.corrcoef(case_studies.transpose())
    cmatrix= case_corr
    fig = plt.figure(figsize=(twocol,twocol),dpi=figdpi,tight_layout=True)
    ax = fig.add_subplot(111)
    ppl.pcolormesh(fig,ax,cmatrix[inds][:,inds],#-np.diag([.99]*len(meths)),
                   yticklabels=np.array(mindex)[inds].tolist(),
                   xticklabels=np.array(mindex)[inds].tolist(),
                   cmap=ppl.mpl.cm.RdBu,vmax=0.4,vmin= -0.4)
    ax.tick_params(axis='both', which='major', labelsize=8)
    plt.setp(ax.get_xticklabels(), rotation='vertical')
    cm=dark2
    [l.set_color(cm[m_codes[mindex.index(l.get_text())]]) for i,l in enumerate(ax.get_yticklabels())]
    [l.set_color(cm[m_codes[mindex.index(l.get_text())]]) for i,l in enumerate(ax.get_xticklabels())]
    fig.show()
    fig.savefig(figure_path+('method_matrix%s.pdf'%fileappend))
    
    #Show the highly correlated methods
    pq=PQ()
    pq_cross=PQ()
    for i in range(len(meths)):
        for j in range(i+1,len(meths)):
            m1text='(%s) %s'%(meths[i,1],meths[i,0])
            m2text='(%s) %s'%(meths[j,1],meths[j,0])
            pq.put((-cmatrix[i,j],(m1text,m2text)))
            if meths[i,1]!= meths[j,1]:
                pq_cross.put((-cmatrix[i,j],(m1text,m2text)))
    
    # Output the method correlations
    # Sets how many highly correlated methods should be displayed
    print_cap = 20
    moutfile = open(results_path+('method_corrs%s.csv'%fileappend),'w')
    print 'All methods:'
    for i in range(pq.qsize()):
        v,(m1,m2)=pq.get()
        if i < print_cap:
            print '%.2f & %s & %s\\\\'%(-v,m1,m2)
        moutfile.write('%.9f | %s | %s\n'%(-v,m1,m2))
    moutfile.close()
    
    moutfile = open(results_path+('method_corrs_cross%s.csv'%fileappend),'w')
    print 'Just cross methods:'
    for i in range(pq_cross.qsize()):
        v,(m1,m2)=pq_cross.get()
        if i < print_cap:
            print '%.2f & %s & %s\\\\'%(-v,m1,m2)
        moutfile.write('%.9f | %s | %s\n'%(-v,m1,m2))
    moutfile.close()
Пример #21
0
 def plot_helper(li, ti, p):
     if ppl == None:
         print >> sys.stderr, "cannot plot this without prettyplotlib"
         return
     fig, ax = plt.subplots(1)
     if li % 2:
         title = "biases" + ti
         ppl.bar(ax, numpy.arange(p.shape[0]), p)  # TODO with plt
     else:
         title = "weights" + ti
         ppl.pcolormesh(fig, ax, p)  # TODO with plt
     plt.title(title)
     plt.savefig(title + ".png")
     #ppl.show()
     plt.close()
Пример #22
0
 def plot_helper(li, ti, p):
     if ppl == None:
         print >> sys.stderr, "cannot plot this without prettyplotlib"
         return
     fig, ax = plt.subplots(1)
     if li % 2:
         title = "biases" + ti
         ppl.bar(ax, numpy.arange(p.shape[0]), p) # TODO with plt
     else:
         title = "weights" + ti
         ppl.pcolormesh(fig, ax, p) # TODO with plt
     plt.title(title)
     plt.savefig(title + ".png")
     #ppl.show()
     plt.close()
Пример #23
0
def test_pcolormesh_positive_other_cmap():
    red_purple = brewer2mpl.get_map("RdPu", "sequential", 8).mpl_colormap

    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(
        fig,
        ax,
        np.random.uniform(size=(10, 10)),
        xticklabels=string.uppercase[:10],
        yticklabels=string.lowercase[-10:],
        cmap=red_purple,
    )
Пример #24
0
def col_map (name, num_color):
    '''
    1) This function is designed to read a color set from ColorBrewer website
       http://bl.ocks.org/mbostock/5577023
    2) Returns the color map

    Note:
        This function requires "brewer2mpl" library.
    '''
    # Get color data from
    color_set = brewer2mpl.get_map(name, 'diverging', num_color,
                                   reverse=True).mpl_colormap
    ax = fig.add_subplot(1,3,2)
    np.random.seed(10)

    ppl.pcolormesh (fig, ax, np.random.randn(10,10),cmap=color_set)
    ax.set_title('Improved color map\nwith ColorBrewer color set',fontsize=11.5)
Пример #25
0
def draw_real_facebb_res():
	from prettyplotlib import brewer2mpl
	from matplotlib.colors import LogNorm
	red_purple = brewer2mpl.get_map('RdPu', 'Sequential', 9).mpl_colormap
	names = ['TREES', 'CFAN', 'RCPR', 'IFA', 'CFSS', 'SDM', 'LBF', 'TCDCN', 'CCNF', 'GNDPM', 'DRMF','CFSS']
	bbsname = ['IBUG','V&J','HOG+SVM','HeadHunter']
	mat = np.loadtxt('expdata/fig_confmatrix.txt')
	fig, ax = plt.subplots(1)
	ppl.pcolormesh(fig, ax, mat.T,xticklabels=names,yticklabels=bbsname)
	bestbbpairs = [2,1,1,0,0,0,2,0,0,1,0]
	for k in range(len(bbsname)):
		for k2 in range(11):
			if bestbbpairs[k2] == k: 
				ax.annotate(('%1.5f'%mat[k2][k])[:6],xy=(k2+0.5,k+0.5),bbox=dict(boxstyle="round", fc="cyan",alpha=0.8),
				  horizontalalignment='center',
					verticalalignment='center')
			else:
				ax.annotate(('%1.5f'%mat[k2][k])[:6],xy=(k2+0.5,k+0.5),
				  horizontalalignment='center',
					verticalalignment='center')
	plt.xlim((0,11))
Пример #26
0
    np.where(
        np.in1d(cities_desc[target_city]['index'],
                reg['properties']['venues']))[0]
    for reg in gold_list[district]['gold'][target_city]
]
print('There are {} corresponding ground truth areas'.format(
    len(gold_target_venues_indices)))

sorted_distances = np.sort(distances, 1)
ordered = np.argsort(distances, 1)
query_order = np.argsort(sorted_distances[:, 50])

fig, ax = plt.subplots(1)
_ = ppl.pcolormesh(fig,
                   ax,
                   sorted_distances[query_order, :],
                   norm=mpl.colors.LogNorm(vmin=sorted_distances[:, 0].min(),
                                           vmax=sorted_distances[:, -1].max()))
barcelona_venues = sorted_distances[query_order, :]
gold_rank_venues = []
tg = 0
for qv in query_order:
    venue_indices_sorted = np.argsort(ordered[qv, :])
    _ = ppl.plot(venue_indices_sorted[gold_target_venues_indices[tg]],
                 qv * np.ones(len(gold_target_venues_indices[tg])) + .5,
                 'kx',
                 ms=6,
                 mew=1.3)
fs = 12
plt.ylabel('Venues in query region', fontsize=fs)
# plt.xlabel('Venues in {}, sorted on each row by distance with the corresponding query venue'.format(target_city.title()), fontsize=16)
Пример #27
0
all_target_features = cities_desc[target_city]['features']

print('Venues in query: {}'.format(len(query_venues)))
print('Venues in target cities: {}'.format(len(all_target_features)))
distances = cdist(query_features, all_target_features)

gold_target_venues_indices = [np.where(np.in1d(cities_desc[target_city]['index'], reg['properties']['venues']))[0]
                              for reg in gold_list[district]['gold'][target_city]]
print('There are {} corresponding ground truth areas'.format(len(gold_target_venues_indices)))

sorted_distances = np.sort(distances, 1)
ordered = np.argsort(distances, 1)
query_order=np.argsort(sorted_distances[:, 50])

fig, ax = plt.subplots(1)
_=ppl.pcolormesh(fig, ax, sorted_distances[query_order, :], norm=mpl.colors.LogNorm(vmin=sorted_distances[:, 0].min(), vmax=sorted_distances[:, -1].max()))
barcelona_venues = sorted_distances[query_order, :]
gold_rank_venues = []
tg=0
for qv in query_order:
    venue_indices_sorted = np.argsort(ordered[qv, :])
    _=ppl.plot(venue_indices_sorted[gold_target_venues_indices[tg]], qv*np.ones(len(gold_target_venues_indices[tg]))+.5, 'kx', ms=6, mew=1.3)
fs=12
plt.ylabel('Venues in query region', fontsize=fs)
# plt.xlabel('Venues in {}, sorted on each row by distance with the corresponding query venue'.format(target_city.title()), fontsize=16)
plt.xlabel('Venues in {}'.format(target_city.title()), fontsize=fs)
title = '{}, from {} to {}\nThe crosses mark position of venues in ground truth region\nThe color encodes distance between venues, the more red the farthest'
#plt.title(title.format(district.title(), query_city.title(), target_city.title()))
_=plt.xlim([0, len(all_target_features)])
ax.tick_params(axis='both', which='major', labelsize=fs)
fig.delaxes(fig.axes[1])
Пример #28
0
  
    xs,ys = np.where(np.isnan(sparse_eps))

    for x,y in zip(xs,ys):
        sparse_eps[x,y] = 0.5

    max1 = np.max(sparse_eps)
    max2 = np.max(dense_eps)
    max3 = np.max(particle_eps)

    maxtotal = np.max([max1,max2,max3])


    min1 = np.min(sparse_eps)
    min2 = np.min(dense_eps)
    min3 = np.min(particle_eps)

    mintotal = np.min([min1,min2,min3])


    fig, (ax1,ax2,ax3) = ppl.subplots(3,1)

    p1 = ppl.pcolormesh(fig,ax1,dense_eps)
    p2 = ppl.pcolormesh(fig,ax2,sparse_eps)
    p3 = ppl.pcolormesh(fig,ax3,particle_eps)

    [p.set_clim(vmin=mintotal,vmax=maxtotal) for p in [p1,p2,p3]]


    plt.show()
Пример #29
0
def test_pcolormesh_labels():
    np.random.seed(10)

    ppl.pcolormesh(np.random.randn(10, 10),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:])
Пример #30
0
time_formatter = ticker.FormatStrFormatter('%ds')
y_formatter = ticker.FormatStrFormatter('%.2f%%')

def x_func_format(x, p):
	return str(int(sizes[p]))

data1 = np.loadtxt(filename)
data2 = np.loadtxt(f2)

data = data1 + data2

sizes_integer = [int(i) for i in sizes]
#data = data.transpose()
cb = ppl.pcolormesh(fig, ax, data,
			   cmap=purples,
			   yticklabels=guard_percentages,
			   xticklabels=sizes_integer,
			  # norm=LogNorm(vmin=data.min(), vmax=data.max())
			   )

plt.title('Both phases')
cb.colorbar.set_label('Execution time')
cb.colorbar.formatter = time_formatter
cb.colorbar.update_ticks()
#ax.xaxis.set_major_formatter(ticker.FuncFormatter(x_func_format))
#ax.set_xticks(sizes)
ax.yaxis.set_major_formatter(y_formatter)
ax.set_xlabel('Size')
ax.set_ylabel('Percentage of guards')

plt.savefig('combined.png', facecolor='#BFBFBF')
Пример #31
0
# Color could represent: count(*), avg(cpc), sum(cpc)

title = "Heatmap of average CPC for each (adId, app)"
adId_indices = execute_sql(
    """SELECT adId FROM ejam GROUP BY adId HAVING AVG(cpc) > 0 ORDER BY COUNT(*) DESC;"""
)
app_indices = execute_sql(
    """SELECT app_id FROM ejam GROUP BY app_id ORDER BY COUNT(*) DESC;""")
adId_indices = dict((k[0], v) for v, k in enumerate(adId_indices))
app_indices = dict((k[0], v) for v, k in enumerate(app_indices))
pp(adId_indices)
pp(app_indices)
r = execute_sql(
    """SELECT adId, app_id, AVG(cpc) FROM ejam GROUP BY adId, app_id HAVING AVG(cpc) > 0;"""
)
pp(r)
matrix = np.zeros((len(adId_indices), len(app_indices)))
for adId, app, value in r:
    if adId in adId_indices and app in app_indices:
        adId = adId_indices[adId]
        app = app_indices[app]
        matrix[adId][app] = value
matrix = matrix.clip(0, 0.15)
pp(matrix)
fig, ax = ppl.subplots(1)
ppl.pcolormesh(fig, ax, matrix)
pyplot.xlabel('App (ordered by frequency)')
pyplot.ylabel('adId (ordered by frequency)')
pyplot.title(title)
pyplot.show()
Пример #32
0
ggplot(df, aes(x="Animal", weight="Legs")) + geom_bar(fill='blue')

# Find this tutorial helpful?  Checkout the blue sidebar for more tutorials!

###############################################################

plt.figure(figsize=(4,3));
np.random.seed(12)
plt.pcolormesh(np.random.rand(16, 16));
plt.colorbar();

#################################################################

plt.figure(figsize=(4,3));
np.random.seed(12);
ppl.pcolormesh(np.random.rand(16, 16));



#################################################################

import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
%matplotlib inline

n = 10  # Number of nodes in the graph.
# Each node is connected to the two next nodes,
# in a circular fashion.
adj = [(i, (i+1)%n) for i in range(n)]
adj += [(i, (i+2)%n) for i in range(n)]
Пример #33
0
title = "Heatmap of average CPC for each (adId, app)"
adId_indices = execute_sql("""SELECT adId FROM ejam GROUP BY adId HAVING AVG(cpc) > 0 ORDER BY COUNT(*) DESC;""")
app_indices = execute_sql("""SELECT app_id FROM ejam GROUP BY app_id ORDER BY COUNT(*) DESC;""")
adId_indices = dict((k[0],v) for v,k in enumerate(adId_indices))
app_indices = dict((k[0],v) for v,k in enumerate(app_indices))
pp(adId_indices)
pp(app_indices)
r = execute_sql("""SELECT adId, app_id, AVG(cpc) FROM ejam GROUP BY adId, app_id HAVING AVG(cpc) > 0;""")
pp(r)
matrix = np.zeros((len(adId_indices), len(app_indices)))
for adId, app, value in r:
  if adId in adId_indices and app in app_indices:
    adId = adId_indices[adId]
    app = app_indices[app]
    matrix[adId][app] = value
matrix = matrix.clip(0, 0.15)
pp(matrix)
fig, ax = ppl.subplots(1)
ppl.pcolormesh(fig, ax, matrix)
pyplot.xlabel('App (ordered by frequency)')
pyplot.ylabel('adId (ordered by frequency)')
pyplot.title(title)
pyplot.show()







Пример #34
0
def test_pcolormesh_negative():
    np.random.seed(10)

    ppl.pcolormesh(-np.random.uniform(size=(10, 10)),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:])
Пример #35
0
import troposave as ta
import prettyplotlib as ppl
import pickle

with open('./pickles/regarr.pickle','rb') as f:
    regarr = pickle.load(f)
# for n in xrange(regarr.shape[0]):
#     regarr[n,:] = regarr[n,:]/(regarr[n,:].std())

pval_reg = np.zeros((regarr.shape[1],regarr.shape[1]))
for n in xrange(regarr.shape[1]):
    for m in xrange(regarr.shape[1]):
#         if n<=m:
        pval_reg[n,m] = np.corrcoef(regarr[0:-4,n],regarr[0:-4,m])[0,1]

var = np.array(['Tsfc','smc clim','T700hPa','T300hpa','RH700hPa','RH300hPa','DLWR','DSWR','smc','Cld High','Cld Low','Precip','u_high','u_low','v_high','v_low'])
regs =np.array(['India','MC','TropSthAm','SthSthAm','NthWestAfr','NthEastAfr','TropAfr','SthAfr','Aus','lat10', 'latN20', 'latS20', 'latN30', 'latS30'])

plt.close('all')
fig, axes = plt.subplots(nrows=1) #,ncols=2)
fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.85, 0.15, 0.02, 0.7])
ppl.pcolormesh(fig, axes, pval_reg, ax_colorbar=cbar_ax, yticklabels=regs, xticklabels=regs,vmin=-1.0,vmax=1.0)
axes.set_xlabel('Regions')
axes.set_ylabel('Regions')
axes.set_title('Correlation between regions for range of variables')
plt.show()
fig.set_size_inches(18,5)
plt.savefig('regresp_cor_manyvar.eps')

Пример #36
0
data = np.loadtxt(open(
    "/home/vanessa/NHRInsightFL/Playlist1DistanceMatrixsmall.csv", "rb"),
                  delimiter=",",
                  skiprows=1)
transformed = []
print data[1]

for line in data:
    transline = []
    for index, bit in enumerate(line):
        transline.append(bit)
    transformed.append(transline)

fig, ax = ppl.subplots(1)

ppl.pcolormesh(fig, ax, data)
fig.savefig('pcolormesh_prettyplotlib_default.png')

# <codecell>

fig, ax = plt.subplots(1)
data = np.loadtxt(open(
    "/home/vanessa/NHRInsightFL/Playlist1DistanceMatrixsmall.csv", "rb"),
                  delimiter=",",
                  skiprows=1)
transformed = []

print
for line in data:
    transline = []
    for index, bit in enumerate(line):
Пример #37
0
def test_pcolormesh_other_cmap():
    purple_green = brewer2mpl.get_map('PRGn', 'diverging', 11).mpl_colormap
    np.random.seed(10)

    ppl.pcolormesh(np.random.randn(10, 10), cmap=purple_green)
Пример #38
0
def test_pcolormesh_lognorm():
    np.random.seed(10)

    x = np.abs(np.random.randn(10, 10))
    ppl.pcolormesh(x,
                   norm=LogNorm(vmin=x.min().min(), vmax=x.max().max()))
Пример #39
0
def test_pcolormesh_other_cmap():
    purple_green = brewer2mpl.get_map('PRGn', 'diverging', 11).mpl_colormap
    np.random.seed(10)

    ppl.pcolormesh(np.random.randn(10, 10), cmap=purple_green)
Пример #40
0
def test_pcolormesh_labels():
    np.random.seed(10)

    ppl.pcolormesh(np.random.randn(10, 10),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:])
Пример #41
0
def test_pcolormesh():
    fig, ax = plt.subplots(1)

    np.random.seed(10)

    ppl.pcolormesh(fig, ax, np.random.randn(10, 10))
Пример #42
0
    regarr[12,n] = lhf_reg[n].data
    regarr[13,n] = shf_reg[n].data
#     regarr[12,n] = u_high_reg[n].data
#     regarr[13,n] = u_low_reg[n].data
#     regarr[14,n] = v_high_reg[n].data
#     regarr[15,n] = v_low_reg[n].data

with open('./pickles/regarr.pickle','wb') as f:
	pickle.dump(regarr,f)

for n in xrange(regarr.shape[0]):
    regarr[n,:] = regarr[n,:]/(regarr[n,:].std())

var = np.array(['Tsfc','smc clim','T700hPa','T300hpa','RH700hPa','RH300hPa','DLWR','DSWR','smc','Cld High','Cld Low','Precip','lhf','shf']) #,'u_high','u_low','v_high','v_low'])
regs =np.array(['India','MC','TropSthAm','SthSthAm','NthWestAfr','NthEastAfr','TropAfr','SthAfr','Aus','lat10', 'latN20', 'latS20', 'latN30', 'latS30'])

plt.close('all')
fig, axes = plt.subplots(nrows=1) #,ncols=2)
fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.85, 0.15, 0.02, 0.7])
ppl.pcolormesh(fig, axes, regarr, ax_colorbar=cbar_ax, yticklabels=var, xticklabels=regs,vmin=-2.6,vmax=2.6)
axes.set_xlabel('Regions')
axes.set_ylabel('variables')
axes.set_title('Response to Max forcing')
plt.show()
fig.set_size_inches(18,5)
plt.savefig('./figures/regional_response_manyvar_max.eps')



Пример #43
0
Plot I: #Make a histogram of the noise
'''
fig = plt.figure(figsize=(8, 8))
fig.subplots_adjust(left=0.11, right=0.95, wspace=0.3, bottom=0.17, top=0.9)
ax = fig.add_subplot(111)
hist(yerr, bins='knuth', ax=ax, normed=True, histtype='stepfilled', alpha=0.4)
ax.set_xlabel('$y_{err}$')
ax.set_ylabel('$p(y_{err})$')
plt.savefig("figures/yerr.pdf")
plt.close()
'''
Plot II: #Make an image of the noise
'''
#Visualize the covariance
fig, ax = plt.subplots(1)
ppl.pcolormesh(fig, ax, true_cov)
fig.savefig('figures/pplLineCov.png')
#plt.show()
plt.close()
'''
Plot III: #Data vs 'truth'
'''
#And plot the data with the observational uncertainties. The true line is plotted in black.
fig = plt.figure(figsize=(6, 6))
fig.subplots_adjust(left=0.11, right=0.95, wspace=0.3, bottom=0.17, top=0.9)

ax = fig.add_subplot(111)
x0 = np.linspace(-6, 6, 1000)
ax.errorbar(x, y, yerr=yerr, fmt=".k", capsize=0)
ax.plot(x0, true_m * x0 + true_b, "k", lw=2, alpha=0.8)
ax.set_ylim(-4, 4)
Пример #44
0
vs_all = data[2][198:]
vs_comm = data[3][198:]
vs_diff = (vs_comm/(vs_all)).reshape((18))

X = np.linspace(2,14,18)

#raw = np.log(raw)

fig, ax = plt.subplots(1)

ax.set_xlabel('Liczba procesow')
ax.set_ylabel('Dlugosc slowa')
cb = ppl.pcolormesh(fig, ax, raw,
			   cmap=purples,
                  xticklabels = [2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 24, 28, 33, 40]
                  ,
                  norm=LogNorm(vmin=raw.min(), vmax=raw.max())
                     )

#plt.plot(X, seq_times)

#ppl.pcolormesh(raw)
plt.show()

plt.clf()

plt.plot(processes, vs_diff)
#plt.xticks(processes, processes)
plt.xlabel('Liczba procesow')
plt.ylabel('Stosunek czasu komunikacji/przetwarzania [0;1]')
Пример #45
0
def plot_method_pairs_and_matrix(case_studies, fileappend=''):
    case_cov = np.cov(case_studies.transpose())
    case_corr = np.corrcoef(case_studies.transpose())
    cmatrix = case_corr
    fig = plt.figure(figsize=(twocol, twocol), dpi=figdpi, tight_layout=True)
    ax = fig.add_subplot(111)
    ppl.pcolormesh(
        fig,
        ax,
        cmatrix[inds][:, inds],  #-np.diag([.99]*len(meths)),
        yticklabels=np.array(mindex)[inds].tolist(),
        xticklabels=np.array(mindex)[inds].tolist(),
        cmap=ppl.mpl.cm.RdBu,
        vmax=0.4,
        vmin=-0.4)
    ax.tick_params(axis='both', which='major', labelsize=8)
    plt.setp(ax.get_xticklabels(), rotation='vertical')
    cm = dark2
    [
        l.set_color(cm[m_codes[mindex.index(l.get_text())]])
        for i, l in enumerate(ax.get_yticklabels())
    ]
    [
        l.set_color(cm[m_codes[mindex.index(l.get_text())]])
        for i, l in enumerate(ax.get_xticklabels())
    ]
    fig.show()
    fig.savefig(figure_path + ('method_matrix%s.pdf' % fileappend))

    #Show the highly correlated methods
    pq = PQ()
    pq_cross = PQ()
    for i in range(len(meths)):
        for j in range(i + 1, len(meths)):
            m1text = '(%s) %s' % (meths[i, 1], meths[i, 0])
            m2text = '(%s) %s' % (meths[j, 1], meths[j, 0])
            pq.put((-cmatrix[i, j], (m1text, m2text)))
            if meths[i, 1] != meths[j, 1]:
                pq_cross.put((-cmatrix[i, j], (m1text, m2text)))

    # Output the method correlations
    # Sets how many highly correlated methods should be displayed
    print_cap = 20
    moutfile = open(results_path + ('method_corrs%s.csv' % fileappend), 'w')
    print 'All methods:'
    for i in range(pq.qsize()):
        v, (m1, m2) = pq.get()
        if i < print_cap:
            print '%.2f & %s & %s\\\\' % (-v, m1, m2)
        moutfile.write('%.9f | %s | %s\n' % (-v, m1, m2))
    moutfile.close()

    moutfile = open(results_path + ('method_corrs_cross%s.csv' % fileappend),
                    'w')
    print 'Just cross methods:'
    for i in range(pq_cross.qsize()):
        v, (m1, m2) = pq_cross.get()
        if i < print_cap:
            print '%.2f & %s & %s\\\\' % (-v, m1, m2)
        moutfile.write('%.9f | %s | %s\n' % (-v, m1, m2))
    moutfile.close()
Пример #46
0
normMax = max(sparql.max().max(),
              cypher.max().max(),
              gremlin.max().max(),
              graphql.max().max())
normMin = min(sparql.min().min(),
              cypher.min().min(),
              gremlin.min().min(),
              graphql.min().min())

# SPARQL

ax1 = fig.add_subplot(grix, griy, 1, label="aaa")

ppl.pcolormesh(fig,
               ax1,
               sparql,
               xticklabels=[0, 1, 2, 3, 4, 5, "+"],
               yticklabels=[0, 1, 2, 3, 4, 5, "+"],
               cmap=sparql_colors)

for (i, j), z in np.ndenumerate(sparql_label):
    ax1.text(0.5 + j,
             0.5 + i,
             '{:d}'.format(z),
             ha='center',
             va='center',
             color='white')

plt.xlabel("SPARQL forks (Ø" + sparql_forks_avg + ")")
plt.ylabel("SPARQL stars (Ø" + sparql_stars_avg + ")")

# Cypher
Пример #47
0
def test_pcolormesh():
    np.random.seed(10)

    ppl.pcolormesh(np.random.randn(10, 10))
Пример #48
0
def test_pcolormesh():
    np.random.seed(10)

    ppl.pcolormesh(np.random.randn(10, 10))
Пример #49
0
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import prettyplotlib as ppl
import numpy as np
import string

fig, ax = plt.subplots(1)

np.random.seed(10)

ppl.pcolormesh(fig,
               ax,
               np.random.randn(10, 10),
               xticklabels=np.array(range(10)),
               yticklabels=string.lowercase[-10:])
fig.savefig('pcolormesh_prettyplotlib_labels.png')
Пример #50
0
def test_pcolormesh_negative():
    np.random.seed(10)

    ppl.pcolormesh(-np.random.uniform(size=(10, 10)),
                   xticklabels=UPPERCASE_CHARS[:10],
                   yticklabels=LOWERCASE_CHARS[-10:])
Пример #51
0
def plot_heatmap(fig, ax, df, field, *args, **kwargs):
    """
    Plots a heatmap of field from dataframe df as a function of parameters
    greediness and synergy.

    Returns a handle to the plot and colorbar axes.

    Parameters:

        fig: figure label

        ax: axis label

        df: pandas DataFrame

        field: string name of DataFrame column to plot

    Optional arguments:
    
        args: additional unnamed parameters passed to pcolormesh
        
    Optional keyword arguments:
    
        kwargs: dictionary of named arguments passed to pcolormesh
    """

    # convert dataframe to 2D array for plotting
    darray, i, c, v, indices, columns = df2ndarray(df, field)
    ax.set_xlabel(c)
    ax.set_ylabel(i)
    ax.set_title(v)

    # if n_players_query == 1000:
    #     Z = darray[:-1,:-10] # without Pichler data use Z = darray[:-1,:-2]
    # else:
    #     Z = darray[:-1,:]
    Z = darray[:, :]

    # adjust colorbar scale for positive data
    kwargs.setdefault('vmax', max(1, Z.max()))
    kwargs.setdefault('vmin', min(0, Z.min()))
    # print(kwargs)

    # LaTeX stylized axes labels
    for j in xrange(len(indices)):
        if j % 4 != 0:
            indices[j] = ''
        else:
            indices[j] = '$' + str(indices[j]) + '$'

    for j in xrange(len(columns)):
        # Label multiples of 5
        if j % 5 != 4:
            columns[j] = ''
        else:
            columns[j] = '$' + str(int(columns[j])) + '$'

    # returning a tuple requires prettyplotlib from github which is numbered 0.1.5
    # but is more recent than version 0.1.7 on PyPi
    p, cbar = ppl.pcolormesh(
        fig,
        ax,
        Z,
        xticklabels=columns,  #xticklabels_rotation='vertical', 
        yticklabels=indices,
        # vmin=min(0,v_min), vmax=max(v_max,1),
        edgecolors='face',  # this seems to corrupt corner of box
        *args,
        **kwargs)

    return p, cbar
Пример #52
0
def test_pcolormesh_lognorm():
    np.random.seed(10)

    x = np.abs(np.random.randn(10, 10))
    ppl.pcolormesh(x, norm=LogNorm(vmin=x.min().min(), vmax=x.max().max()))
Пример #53
0
def test_pcolormesh_axes():
    np.random.seed(10)
    x = np.arange(0, 100, 10)
    y = np.arange(0, 20, 2)

    ppl.pcolormesh(x, y, np.random.randn(10, 10))
Пример #54
0
def test_pcolormesh_axes():
    np.random.seed(10)
    x=np.arange(0,100,10)
    y=np.arange(0,20,2)

    ppl.pcolormesh(x, y, np.random.randn(10, 10))
def visualizeSequentialOutput(model, layerIdx, df):

    if not os.path.exists(cc.cfg['plots']['seq_output_dir']):
        os.makedirs(cc.cfg['plots']['seq_output_dir'])


    if cc.cfg['plots']['seq_output_seq_input_name'] == 'smiles':
        input = data.formatSequentialInput(df)
    elif cc.cfg['plots']['seq_output_seq_input_name'] == 'fasta':
        input = data.formatFastaInput(df)
    else:
        raise 'visual err'


    # model.layers[layerIdx].return_sequences = True
    # model.compile(loss="mean_squared_error", optimizer="rmsprop")


    cfg = model.get_config()[:4]

    cfg = model.get_config()[:layerIdx+1]
    del cfg[2]
    layerIdx -= 1

    # print cfg
    cfg[layerIdx]['config']['return_sequences'] = True

    seqModel = Sequential.from_config(cfg)
    seqModel.set_weights(model.get_weights())
    seqModel.layers[layerIdx].return_sequences = True


    outputFunction = K.function([seqModel.layers[0].input],
              [seqModel.layers[layerIdx].output])

    output = outputFunction([input])[0]

    '''
    sns.set()
    for i,smilesOutput in enumerate(output):
        g = sns.clustermap(smilesOutput.T, col_cluster=False,  method='single',metric='cosine')
        g.savefig('{}/seq_output.png'.format(cc.cfg['plots']['seq_output_dir']))
    '''

    dropSet = Set(cc.cfg['plots']['seq_output_ignore_neurons'])
    if cc.cfg['plots']['seq_output_select_neurons']:
        arrMask = cc.cfg['plots']['seq_output_select_neurons']
    else:
        arrMask = list(range(output.shape[2]))
    arrMask = np.array([x for x in arrMask if not x in dropSet])

    fig = plt.figure(figsize=(input.shape[1] * 0.3,len(arrMask) * len(df) * 1.5))


    for i,seqOutput in enumerate(output):

        # print seqOutput.shape
        # print seqOutput

        selected = seqOutput.T[arrMask]

        Z = sch.linkage(selected, method='single', metric='cosine')
        leaves = sch.leaves_list(Z)
        # leaves = range(len(selected))
        reordered = selected[leaves]

        ax = fig.add_subplot(len(df),1,i+1)

        print 'foo'

        ppl.pcolormesh(fig, ax, reordered,
               xticklabels=list(df.values[i][0]),
               yticklabels=arrMask[leaves],
               vmin=-1,
               vmax=1)

        print 'foo'

    print 'bar'

    fig.savefig('{}/{}'.format(cc.cfg['plots']['seq_output_dir'],cc.cfg['plots']['seq_output_name']))

    print 'bar'