Exemplo n.º 1
0
 def timestep(self,data):
     if type(data)==QtCore.QString:
         data=json.loads(unicode(data))
     timestamp=float(data["data"]["stat"]["time"])
     #if (self.app.tab.currentIndex()==2 ):
     if (2==2):
         self.figure.clf()
         ax=self.figure.add_subplot(111)
         self.figure.set_frameon(False)
         ax.patch.set_alpha(0)
         ax.set_xlabel("Time [s]")
         ax.set_ylabel("Image Count")
         try:   
             ppl.hist(ax,self.histdata-np.ceil(timestamp),bins=100,range=(-100,0))
         except (ValueError,AttributeError):
             pass
         ax.set_xlim((-100,0))
         if size(self.histdata)>100:
             speed = -100./(self.histdata[size(self.histdata)-101]-self.histdata[size(self.histdata)-1])
         else:
             speed = 0
         tstr= datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
         ax.set_title(tstr +", "+ str(data["data"]["stat"]['images processed'])+" Images Processed @"+ str(speed) + "fps")
         self.figure.tight_layout()
         self.canvas.draw()
Exemplo n.º 2
0
 def timestep(self, data):
     if type(data) == QtCore.QString:
         data = json.loads(unicode(data))
     timestamp = float(data["data"]["stat"]["time"])
     #if (self.app.tab.currentIndex()==2 ):
     if (2 == 2):
         self.figure.clf()
         ax = self.figure.add_subplot(111)
         self.figure.set_frameon(False)
         ax.patch.set_alpha(0)
         ax.set_xlabel("Time [s]")
         ax.set_ylabel("Image Count")
         try:
             ppl.hist(ax,
                      self.histdata - np.ceil(timestamp),
                      bins=100,
                      range=(-100, 0))
         except (ValueError, AttributeError):
             pass
         ax.set_xlim((-100, 0))
         if size(self.histdata) > 100:
             speed = -100. / (self.histdata[size(self.histdata) - 101] -
                              self.histdata[size(self.histdata) - 1])
         else:
             speed = 0
         tstr = datetime.datetime.fromtimestamp(timestamp).strftime(
             '%Y-%m-%d %H:%M:%S')
         ax.set_title(tstr + ", " +
                      str(data["data"]["stat"]['images processed']) +
                      " Images Processed @" + str(speed) + "fps")
         self.figure.tight_layout()
         self.canvas.draw()
Exemplo n.º 3
0
def pairs(name, data, labels=None):
    """ Generate something similar to R `pairs` """
    nvariables = data.shape[1]
    mpl.rcParams["figure.figsize"] = 3.5 * nvariables, 3.5 * nvariables
    if labels is None:
        labels = ["var {}".format(i) for i in range(nvariables)]
    fig = plt.figure()
    s = clock()
    for i in range(nvariables):
        for j in range(i, nvariables):
            nsub = i * nvariables + j + 1
            ax = fig.add_subplot(nvariables, nvariables, nsub)
            ax.tick_params(left="off", bottom="off", right="off", top="off", labelbottom="off", labelleft="off")
            ax.spines["top"].set_visible(False)
            ax.spines["left"].set_linewidth(0.5)
            ax.spines["bottom"].set_linewidth(0.5)
            ax.spines["right"].set_visible(False)
            if i == j:
                ppl.hist(ax, data[:, i], grid="y")
                ax.set_title(labels[i], fontsize=10)
            else:
                ax.set_xlim([data[:, i].min(), data[:, i].max()])
                ax.set_ylim([data[:, j].min(), data[:, j].max()])
                ax.scatter(data[:, i], data[:, j], marker=".", color="k", s=4)
            ax.tick_params(labelbottom="off", labelleft="off")
    print(clock() - s)
    s = clock()
    plt.savefig(name + "_corr.png", dpi=96, transparent=False, frameon=False, bbox_inches="tight", pad_inches=0.1)
    print(clock() - s)
Exemplo n.º 4
0
def test_scatter():
    # Set the random seed for consistency
    np.random.seed(12)

    # Show some color range
    for i in range(2):
        x = np.random.randn(1000)
        ppl.hist(x)
Exemplo n.º 5
0
def test_scatter():
    # Set the random seed for consistency
    np.random.seed(12)

    # Show some color range
    for i in range(2):
        x = np.random.randn(1000)
        ppl.hist(x)
Exemplo n.º 6
0
def test_scatter():
    # Set the random seed for consistency
    np.random.seed(12)

    fig, ax = plt.subplots(1)

    # Show some color range
    for i in range(2):
        x = np.random.randn(1000)
        ppl.hist(ax, x)
Exemplo n.º 7
0
def hist(data, xtext, ttext, figname):
    #mpl.use('PDF')
    import matplotlib.pyplot as plt, prettyplotlib as ppl

    fig, ax = plt.subplots(1)
    ppl.hist(ax, data[~np.isnan(data)], bins=20, grid='y')
    plt.ylabel('Pixel Number', fontsize=14)
    plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
    plt.xlabel(xtext, fontsize=14)
    plt.title('Histogram of ' + ttext, fontsize=16)
    fig.savefig('afr_' + figname + '_his.pdf', dpi=300)
    plt.close()
Exemplo n.º 8
0
Arquivo: p3.py Projeto: Xqua/CS181
 def Plot_Histogram(self):
     c = Counter()
     for i in range(len(self.df)):
         u = self.df['user'][i]
         c[u] += self.df['plays'][i]
     res = []
     for u in c.keys():
         res.append(c[u])
     ppl.hist(np.log10(res), bins=100)
     plt.xlabel('Log10(Number of play)')
     plt.ylabel('N')
     plt.show()
Exemplo n.º 9
0
def hist(data, xtext, ttext, figname):
    #mpl.use('PDF')
    import matplotlib.pyplot as plt, prettyplotlib as ppl
    
    fig, ax = plt.subplots(1)
    ppl.hist(ax, data[~np.isnan(data)], bins=20, grid='y')
    plt.ylabel('Pixel Number',  fontsize=14)
    plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
    plt.xlabel(xtext,  fontsize=14)
    plt.title('Histogram of '+ttext, fontsize=16)
    fig.savefig('afr_'+figname+'_his.pdf', dpi = 300)
    plt.close()
def plot_patchset_histogram(changes, outputfile=None):
    number_of_patchsets = []
    for change in changes:
        number_of_patchsets.append(len(change['patchSets']))
    fig = plt.figure()
    ax = fig.add_subplot(111)
    hist(ax, number_of_patchsets, bins=np.max(number_of_patchsets))
    ax.set_xlabel('Number of Patch Sets')
    ax.set_ylabel('Change Count')
    ax.set_xlim(0, 20)
    if outputfile:
        fig.savefig(outputfile)
    else:
        plt.show()
Exemplo n.º 11
0
def makehist(series,rejected,mincount=0,bins=[],title="",filename="_"):
    rej = rejected == 1
    app = rejected == 0
    #nrej = sum(rej)*1.0
    #napp = sum(app)*1.0
    
    
    #series_rej = pd.Series({count: sum(series[rej]==count) for count in pd.unique(series[rej])})
    #series_app = pd.Series({count: sum(series[app]==count) for count in pd.unique(series[app])})

    #rej_plot = series_rej[series_rej.index>=mincount]/nrej
    #app_plot = series_app[series_app.index>=mincount]/napp
    fig, ax = plt.subplots(1)
    
    if len(bins) > 0:
        ppl.hist(ax,np.array(series[app]),bins=bins,label='approved',color=color_approved,alpha=0.8)
        ppl.hist(ax,np.array(series[rej]),bins=bins,label='rejected',color=color_rejected,alpha=0.4)

        #n1,bin1,_ = ppl.hist(ax,np.array(rej_plot.index),bins=bins,weights=np.array(rej_plot),label='rejected')
        #n2,bin2,_ = ppl.hist(ax,np.array(app_plot.index),bins=bins,weights=np.array(app_plot),label='approved')
    else:        
        ppl.hist(ax,np.array(series[app]),label='approved',color=color_approved,alpha=0.8)
        ppl.hist(ax,np.array(series[rej]),label='rejected',color=color_rejected,alpha=0.4)
        
        #n1,bin1,_ = ppl.hist(ax,np.array(rej_plot.index),weights=np.array(rej_plot),label='rejected')
        #n2,bin2,_ = ppl.hist(ax,np.array(app_plot.index),weights=np.array(app_plot),label='approved')
    plt.legend()
    if mincount > 0:
        title = title + "(count >= " + str(mincount) + ")"
    plt.title(title)
    
    filepath = dl.getDataFilePath('plots/fig_'+filename+'.png')
    plt.savefig(filepath)
    
    plt.show()
Exemplo n.º 12
0
    def plot_histogram(self, ax, x, bins, title='', xlabel='', title_font={},
                       axis_font={}, tick_font={}, **kwargs):

        if not title_font:
            title_font = title_font_default
        if not axis_font:
            axis_font = axis_font_default
        x = x[~np.isnan(x)]
        ppl.hist(ax, x, bins, grid='y', **kwargs)
        if xlabel:
            ax.set_xlabel(xlabel.replace("_", " "), labelpad=10, **axis_font)
        if tick_font:
            ax.tick_params(**tick_font)
        ax.set_ylabel('No. of Occurrences', **axis_font)
        ax.set_title(title.replace("_", " "), **title_font)
Exemplo n.º 13
0
def _print_and_plot(mean_alpha, mean_beta, alphas, betas, n_iter, data):
    print
    print mean_alpha, mean_beta, '  estimated modality:', \
        _assign_modality_from_estimate(mean_alpha, mean_beta)

    import numpy as np
    from scipy.stats import beta
    import matplotlib.pyplot as plt
    import prettyplotlib as ppl

    fig, axes = plt.subplots(ncols=2, figsize=(12, 4))
    ax = axes[0]

    ppl.plot(alphas, label='alpha', ax=ax)
    ppl.plot(betas, label='beta', ax=ax)
    ppl.legend(ax=ax)
    ax.hlines(mean_alpha, 0, n_iter)
    ax.hlines(mean_beta, 0, n_iter)
    ax.annotate('mean_alpha = {:.5f}'.format(mean_alpha), (0, mean_alpha),
                fontsize=12,
                xytext=(0, 1),
                textcoords='offset points')
    ax.annotate('mean_beta = {:.5f}'.format(mean_alpha), (0, mean_beta),
                fontsize=12,
                xytext=(0, 1),
                textcoords='offset points')
    ax.set_xlim(0, n_iter)

    ax = axes[1]
    ppl.hist(data,
             facecolor='grey',
             alpha=0.5,
             bins=np.arange(0, 1, 0.05),
             zorder=10,
             ax=ax)
    ymin, ymax = ax.get_ylim()
    one_x = np.arange(0, 1.01, 0.01)
    x = np.repeat(one_x, n_iter).reshape(len(one_x), n_iter)
    beta_distributions = np.vstack(
        (beta(a, b).pdf(one_x) for a, b in zip(alphas, betas))).T

    ppl.plot(x,
             beta_distributions,
             color=ppl.colors.set2[0],
             alpha=0.1,
             linewidth=2,
             ax=ax)
    ax.set_ylim(0, ymax)
Exemplo n.º 14
0
def plot_dist(vars,names,title=''):
    k = len(names)
    fig,ax = subplots(1,k, figsize=(4*k,4))
    for i in range(k):
        m = np.mean(vars[i])
        s = np.std(vars[i])
        at = get_label("$\mu$ = %2.2f\n$\sigma$ = %2.2f"%(m,s))
        if not k ==1:
            ppl.hist(ax[i],vars[i])
            ax[i].set_xlabel(names[i])
            ax[i].add_artist(at)
        else:
            ppl.hist(ax,vars[i])
            ax.set_xlabel(names[i])
            ax.add_artist(at)
    suptitle(title,size=14)
Exemplo n.º 15
0
    def timestep(self,resultstr):
        data=json.loads(unicode(resultstr))
        timestamp=data["data"]["stat"]["time"]
     
        if (   self.app.tab.currentIndex()==2 ):
            self.figure.clf()
            ax=self.figure.add_subplot(111)
            self.figure.set_frameon(False)
            ax.patch.set_alpha(0)
            ax.set_xlabel("Time [s]")
            ax.set_ylabel("Image Count")
            ppl.hist(ax,self.histdata-np.ceil(timestamp),bins=100,range=(-100,0))
            ax.set_xlim((-100,0))
            tstr= datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
            ax.set_title(tstr +", "+ str(data["data"]["stat"]['images processed'])+" Images Processed")

            self.canvas.draw()
Exemplo n.º 16
0
    def timestep(self, data):
        if type(data) == QtCore.QString:
            data = json.loads(unicode(data))
        timestamp = float(data["data"]["stat"]["time"])
        print timestamp
        if self.app.tab.currentIndex() == 2:
            self.figure.clf()
            ax = self.figure.add_subplot(111)
            self.figure.set_frameon(False)
            ax.patch.set_alpha(0)
            ax.set_xlabel("Time [s]")
            ax.set_ylabel("Image Count")
            ppl.hist(ax, self.histdata - np.ceil(timestamp), bins=100, range=(-100, 0))
            ax.set_xlim((-100, 0))
            tstr = datetime.datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
            ax.set_title(tstr + ", " + str(data["data"]["stat"]["images processed"]) + " Images Processed")

            self.canvas.draw()
Exemplo n.º 17
0
def pairs(name, data, labels=None):
    """ Generate something similar to R `pairs` """
    nvariables = data.shape[1]
    mpl.rcParams['figure.figsize'] = 3.5 * nvariables, 3.5 * nvariables
    if labels is None:
        labels = ['var {}'.format(i) for i in range(nvariables)]
    fig = plt.figure()
    s = clock()
    for i in range(nvariables):
        for j in range(i, nvariables):
            nsub = i * nvariables + j + 1
            ax = fig.add_subplot(nvariables, nvariables, nsub)
            ax.tick_params(left='off',
                           bottom='off',
                           right='off',
                           top='off',
                           labelbottom='off',
                           labelleft='off')
            ax.spines['top'].set_visible(False)
            ax.spines['left'].set_linewidth(0.5)
            ax.spines['bottom'].set_linewidth(0.5)
            ax.spines['right'].set_visible(False)
            if i == j:
                ppl.hist(ax, data[:, i], grid='y')
                ax.set_title(labels[i], fontsize=10)
            else:
                ax.set_xlim([data[:, i].min(), data[:, i].max()])
                ax.set_ylim([data[:, j].min(), data[:, j].max()])
                ax.scatter(data[:, i], data[:, j], marker='.', color='k', s=4)
            ax.tick_params(labelbottom='off', labelleft='off')
    print(clock() - s)
    s = clock()
    plt.savefig(name + '_corr.png',
                dpi=96,
                transparent=False,
                frameon=False,
                bbox_inches='tight',
                pad_inches=0.1)
    print(clock() - s)
Exemplo n.º 18
0
def _print_and_plot(mean_alpha, mean_beta, alphas, betas, n_iter, data):
    print
    print mean_alpha, mean_beta, '  estimated modality:', \
        _assign_modality_from_estimate(mean_alpha, mean_beta)

    import numpy as np
    from scipy.stats import beta
    import matplotlib.pyplot as plt
    import prettyplotlib as ppl

    fig, axes = plt.subplots(ncols=2, figsize=(12, 4))
    ax = axes[0]

    ppl.plot(alphas, label='alpha', ax=ax)
    ppl.plot(betas, label='beta', ax=ax)
    ppl.legend(ax=ax)
    ax.hlines(mean_alpha, 0, n_iter)
    ax.hlines(mean_beta, 0, n_iter)
    ax.annotate('mean_alpha = {:.5f}'.format(mean_alpha),
                (0, mean_alpha), fontsize=12,
                xytext=(0, 1), textcoords='offset points')
    ax.annotate('mean_beta = {:.5f}'.format(mean_alpha),
                (0, mean_beta), fontsize=12,
                xytext=(0, 1), textcoords='offset points')
    ax.set_xlim(0, n_iter)

    ax = axes[1]
    ppl.hist(data, facecolor='grey', alpha=0.5, bins=np.arange(0, 1, 0.05),
             zorder=10, ax=ax)
    ymin, ymax = ax.get_ylim()
    one_x = np.arange(0, 1.01, 0.01)
    x = np.repeat(one_x, n_iter).reshape(len(one_x), n_iter)
    beta_distributions = np.vstack((beta(a, b).pdf(one_x)
                                    for a, b in zip(alphas, betas))).T

    ppl.plot(x, beta_distributions, color=ppl.colors.set2[0], alpha=0.1,
             linewidth=2, ax=ax)
    ax.set_ylim(0, ymax)
Exemplo n.º 19
0
    def plot_histogram(self,
                       ax,
                       x,
                       bins,
                       title='',
                       xlabel='',
                       title_font={},
                       axis_font={},
                       tick_font={},
                       **kwargs):

        if not title_font:
            title_font = title_font_default
        if not axis_font:
            axis_font = axis_font_default
        x = x[~np.isnan(x)]
        ppl.hist(ax, x, bins, grid='y', **kwargs)
        if xlabel:
            ax.set_xlabel(xlabel.replace("_", " "), labelpad=10, **axis_font)
        if tick_font:
            ax.tick_params(**tick_font)
        ax.set_ylabel('No. of Occurrences', **axis_font)
        ax.set_title(title.replace("_", " "), **title_font)
Exemplo n.º 20
0
    def timestep(self, resultstr):
        data = json.loads(unicode(resultstr))
        timestamp = data["data"]["stat"]["time"]

        if (self.app.tab.currentIndex() == 2):
            self.figure.clf()
            ax = self.figure.add_subplot(111)
            self.figure.set_frameon(False)
            ax.patch.set_alpha(0)
            ax.set_xlabel("Time [s]")
            ax.set_ylabel("Image Count")
            ppl.hist(ax,
                     self.histdata - np.ceil(timestamp),
                     bins=100,
                     range=(-100, 0))
            ax.set_xlim((-100, 0))
            tstr = datetime.datetime.fromtimestamp(timestamp).strftime(
                '%Y-%m-%d %H:%M:%S')
            ax.set_title(tstr + ", " +
                         str(data["data"]["stat"]['images processed']) +
                         " Images Processed")

            self.canvas.draw()
Exemplo n.º 21
0
        if i % 1000 == 0: print 'iteration', i

        samples[:, i] = xx.copy().ravel()

    return samples


w_0 = np.array([0., 1., 1., 1., 1., 1., 1., 1., 1., 1.])

# actually do the sampling
n = 10
sigma = np.ones(10)
samples = slice_sample(w_0, iters=n, sigma=sigma)
v = samples[0, :]

fig, (ax0, ax1) = plt.subplots(2, 1)

# show values of sampled v by iteration
pplt.plot(ax0, np.arange(n), v)
ax0.set_xlabel('iteration number')
ax0.set_ylabel('value of sampled v')

# plot a histogram of values of v
pplt.hist(ax1, v, bins=80)
ax1.set_xlabel('values of sampled v')
ax1.set_ylabel('observations')

plt.tight_layout()
plt.show()
Exemplo n.º 22
0
                         np.logical_or(
                             np.isinf(em_rate[r]),
                             np.isnan(em_rate[r])))]
     qn_rate[r] = qn_rate[r][
                     np.logical_not(
                         np.logical_or(
                             np.isinf(qn_rate[r]),
                             np.isnan(qn_rate[r])))]
     em_rate[r] = em_rate[r][em_rate[r]>=0]
     qn_rate[r] = qn_rate[r][qn_rate[r]>=0]
     em_rate[r] = em_rate[r][em_rate[r]<2]
     qn_rate[r] = qn_rate[r][qn_rate[r]<2]
 #fig, ax = plt.subplots(1)
 #labels=[initnames[i]+': EM' for i in range(numinits)]+[initnames[i]+': QN2' for i in range(numinits)]
 labels = ['EM','QN2']
 ppl.hist(ax4,[np.concatenate(em_rate),np.concatenate(qn_rate)],label=labels)
 ax4.set_title("(d)  "+title+"histogram of convergence rates")
 ax4.set_ylabel('frequency')
 ax4.set_xlabel('convergence rate r')
 ax4.legend()
 #plt.show()
 
 '''
 #fig, ax = plt.subplots(1)
 for i in range(numinits):
     em_k[i][em_k[i]==0] = 1
     qn_k[i][qn_k[i]==0] = 1
 em_time_k_ratio = [np.log10(em_times[i]/em_k[i]*1e6) for i in range(numinits)]
 qn_time_k_ratio = [np.log10(qn_times[i]/qn_k[i]*1e6) for i in range(numinits)]
 #labels=[initnames[i]+': EM' for i in range(numinits)]+[initnames[i]+': QN2' for i in range(numinits)]
 labels = ['EM','QN2']
Exemplo n.º 23
0
    def make_scatter(self, use_prettyplotlib=True, hists=True, num_bins=None):
        '''
        Plot two columns against each other. If self.subplot is enabled,
        all comparisons returned in a triangle collection. Inspiration for
        this form came from the package ![triangle.py](https://github.com/dfm/triangle.py).
        Small snippets to set the labels and figure size came from triangle.py.
        '''

        if use_prettyplotlib:
            try:
                import prettyplotlib as plt
            except ImportError:
                import matplotlib.pyplot as plt
                use_prettyplotlib = False
                print "prettyplotlib not installed. Using matplotlib..."
        else:
            import matplotlib.pyplot as plt

        # Setup subplots if plotting together
        if self.subplot:
          # Make the objects
          num = len(self.columns)
          factor = 2.0 # size of one side of one panel
          lbdim = 0.5 * factor # size of left/bottom margin
          trdim = 0.3 * factor # size of top/right margin
          whspace = 0.05 # w/hspace size
          plotdim = factor * num + factor * (num - 1.) * whspace
          dim = lbdim + plotdim + trdim
          fig, axes = plt.subplots(nrows=num, ncols=num, figsize=(dim, dim))

          lb = lbdim / dim
          tr = (lbdim + plotdim) / dim
          fig.subplots_adjust(left=lb, bottom=lb, right=tr, top=tr,
                              wspace=whspace, hspace=whspace)

        for i, column1 in enumerate(self.columns):
          for j, column2 in enumerate(self.columns):

            data1 = self.dataframe[column1]
            data2 = self.dataframe[column2]

            # Get rid of nans
            nans = np.isnan(data1) + np.isnan(data2)
            data1 = data1[~nans]
            data2 = data2[~nans]

            if self.subplot:
              ax = axes[i, j]
              if j > i: # Don't bother plotting duplicates
                ax.set_visible(False)
                ax.set_frame_on(False)
              else:

                if j == i: # Plot histograms
                  # Set number of bins
                  if num_bins is None:
                      num_bins = np.sqrt(len(data1))
                  if hists == True:
                    if use_prettyplotlib:
                      plt.hist(ax, data1, num_bins, grid="y")
                    else:
                      ax.hist(data1, num_bins)
                      ax.grid(True)
                  else:
                    ax.set_visible(False)
                    ax.set_frame_on(False)

                  ax.set_xticklabels([])
                  ax.set_yticklabels([])

                if j != i:
                  if use_prettyplotlib:
                    plt.scatter(ax, data2, data1)
                  else:
                    ax.scatter(data2, data1)
                  ax.grid(True)
                  ax.xaxis.set_major_locator(MaxNLocator(5))
                  ax.yaxis.set_major_locator(MaxNLocator(5))

                if i < num - 1:
                    ax.set_xticklabels([])
                else:
                    [l.set_rotation(45) for l in ax.get_xticklabels()]
                    ax.set_xlabel(column2)
                    ax.xaxis.set_label_coords(0.5, -0.3)

                if j > 0:
                    ax.set_yticklabels([])
                else:
                    [l.set_rotation(45) for l in ax.get_yticklabels()]
                    ax.set_ylabel(column1)
                    ax.yaxis.set_label_coords(-0.3, 0.5)

            else:
              if j < i:
                fig, axes = plt.subplots(1)
                if use_prettyplotlib:
                  plt.scatter(axes, data2, data1, grid="y")
                else:
                  axes.scatter(data2, data1)
                  axes.grid(True)
                axes.set_xlabel(column2)  # ADD UNITS!
                axes.set_ylabel(column1)  # ADD UNITS!

                if self.verbose:
                  p.show()
                else:
                  fig.savefig(self.save_name+"_"+column1+"_"+column2+"."+self.save_type)
                  p.close()

        if self.subplot:
          # p.tight_layout()
          if self.verbose:
            p.show()
          else:
            fig.savefig(self.save_name+"_"+"scatter"+"."+self.save_type)
#bff = bff[bff.columns.values.tolist()[1:]


# In[12]:

opg.head()


# In[13]:

#Histograms
import prettyplotlib as ppl
#for i in bff.columns.values.tolist():
    print i
    ppl.hist(bff[i],bins=20)
    ppl.plt.savefig(i+'.png')
    ppl.plt.close()


# In[14]:

opg_subset =  [
 'PBR_1+',
 'PBR_2-',
 'PBR_3+',
 'PBR_4+',
 'PBR_5+',
 'PBR_7-',
 'OPG_10+',
 'OPG_12+',
fig.set_size_inches(14, 8)

# <markdowncell>

# ### Number of stations available by number of years

# <codecell>

fig, ax = plt.subplots(1)
year_list_map = []
for s in station_list:
    if "data" in s:
        years = s["data"].keys()
        year_list_map.append(len(years))

ppl.hist(ax, np.array(year_list_map), grid='y')
plt.plot([num_years_required, num_years_required], [0, 8], 'r-', lw=2)
ax.set_ylabel("Number of Stations")
ax.set_xlabel("Number of Years Available")
ax.set_title('Number of available stations vs available years\n'
             '(for bounding box) - red is minimum requested years')

# <markdowncell>

# ## Get model output from OPeNDAP URLS
# ### Try to open all the OPeNDAP URLS using Iris from the British Met Office. If we can open in Iris, we know it's a model result.
# 
# #### Construct an Iris contraint to load only cubes that match the standard names:

# <codecell>
Exemplo n.º 26
0
fig.set_size_inches(14, 8)

# <markdowncell>

# ### Number of stations available by number of years

# <codecell>

fig, ax = plt.subplots(1)
year_list_map = []
for s in station_list:
    if "data" in s:
        years = s["data"].keys()
        year_list_map.append(len(years))

ppl.hist(ax, np.array(year_list_map), grid='y')
plt.plot([num_years_required, num_years_required], [0, 8], 'r-', lw=2)
ax.set_ylabel("Number of Stations")
ax.set_xlabel("Number of Years Available")
ax.set_title('Number of available stations vs available years\n'
             '(for bounding box) - red is minimum requested years')

# <markdowncell>

# ## Get model output from OPeNDAP URLS
# ### Try to open all the OPeNDAP URLS using Iris from the British Met Office. If we can open in Iris, we know it's a model result.
#
# #### Construct an Iris contraint to load only cubes that match the standard names:

# <codecell>
Exemplo n.º 27
0
opg.head()

# In[23]:

opg_col = [
    'PBR_1+', 'PBR_2-', 'PBR_3+', 'PBR_4+', 'PBR_5+', 'PBR_6-', 'PBR_7-',
    'PBR_8-', 'OPG_9+', 'OPG_10+', 'OPG_11-', 'OPG_12+', 'OPG_13+', 'OPG_14+',
    'OPG_15+', 'OPG_16+', 'OPG_17-', 'OPG_18-', 'IE_19+', 'IE_20+', 'IE_21+',
    'IE_22-', 'IE_23-', 'IE_24+', 'IE_25-', 'IE_26-'
]

# In[24]:

for col in opg_col:
    print col
    ppl.hist(opg[col], bins=20)
    ppl.plt.savefig('OPG' + col + '.png')
    ppl.plt.close()

# In[30]:

bff_cols = [
    'BF-F1+', 'BF-F2+', 'BF-F3+', 'BF-F4+', 'BF-F5+', 'BF-F6-', 'BF-F7+',
    'BF-F8+', 'BF-F9+', 'BF-F10+', 'BF-F11+', 'BF-F12+', 'BF-F13+', 'BF-F14+',
    'BF-F15+', 'BF-F16+', 'BF-F17-', 'BF-F18+', 'BF-F19-', 'BF-F20+',
    'BF-F21+', 'BF-F22+', 'BF-F23+', 'BF-F24+', 'BF-F25+', 'BF-F26+',
    'BF-F27+', 'BF-F28-', 'BF-F29+', 'BF-F30+', 'BF-F31+', 'BF-F32+',
    'BF-F33+', 'BF-F34-', 'BF-F35-', 'BF-F36-', 'BF-F37-', 'BF-F38-',
    'BF-F39-', 'BF-F40+', 'BF-F41+', 'BF-F42+', 'BF-F43+', 'BF-F44-',
    'BF-F45-', 'BF-F46-', 'BF-F47-', 'BF-F48-', 'BF-F49-', 'BF-F50+',
    'BF-F51-', 'BF-F52+', 'BF-F53+', 'BF-F54+', 'BF-F55+', 'BF-F56-',
 'IE_20+',
 'IE_21+',
 'IE_22-',
 'IE_24+',
 'IE_25-',
]
opg = opg[dropped_opg2]


# In[16]:

#Histograms
import prettyplotlib as ppl
#for i in bfas.columns.values.tolist()[1:]:
    print i
    ppl.hist(bfas[i],bins=15)
    ppl.plt.savefig(i+'.png')
    ppl.plt.close()


# In[17]:

#Histograms
import prettyplotlib as ppl
#for i in opg.columns.values.tolist()[1:]:
    print i
    ppl.hist(opg[i],bins=15)
    ppl.plt.savefig(i+'.png')
    ppl.plt.close()

	fig, ax = plt.subplots(1)
	ppl.scatter(ax, sumpeak, suminterval)
	ax.set_title(savefilename + ' Heterogeneity distrubition')
	fig.savefig(pathfilename + '_Heterogeneity_distrubition' + '.png',dpi=500)
	plt.close()
	print 'Saved scatter plot:', savefilename

	csvsumpeak = np.sort(sumpeak)
	np.save(pathfilename+'_sorted_Peak', csvsumpeak)
	np.savetxt(pathfilename+'_sorted_Peak.csv', csvsumpeak, delimiter=',')
	print 'Saved sorted Peak:', savefilename

	csvsumpeakdiff = np.diff(csvsumpeak)
	bins = np.sqrt(len(csvsumpeakdiff))
	fig, ax = plt.subplots(1)
	ppl.hist(ax, csvsumpeakdiff, bins = bins)
	ax.set_title(savefilename + ' difference distrubition')
	fig.savefig(pathfilename + '_difference_distrubition' + '.png',dpi=500)
	plt.close()








'''
def determinse(result, precentage):
	attempt = np.zeros(20)
	count = 0
Exemplo n.º 30
0
    def make_hists(self, num_bins=None, use_prettyplotlib=True):

        if use_prettyplotlib:
            try:
                import prettyplotlib as plt
            except ImportError:
                import matplotlib.pyplot as plt
                use_prettyplotlib = False
                print "prettyplotlib not installed. Using matplotlib..."
        else:
            import matplotlib.pyplot as plt

        # Setup subplots if plotting together
        if self.subplot:
            num = len(self.columns)
            if num <= 3:
                ncols = 1
                nrows = num
            elif num <= 8:
                ncols = 2
                nrows = num / 2
            else:  # Max columns right now is 12
                ncols = 3
                nrows = num / 3
            # Check if we need an extra row.
            if num % ncols != 0:
                nrows += 1

            # Make the objects
            fig, axes = plt.subplots(nrows=nrows, ncols=ncols)

            # This is a bit awkward to get the indices, but my matplotlib version
            # doesn't use the same object type as prettyplotlib creates.
            posns = np.indices(axes.shape)
            x, y = posns[0].ravel(), posns[1].ravel()

        # Keep the mean, median, std.
        data_stats = {}
        for i, column in enumerate(self.columns):
            data = self.dataframe[column]
            data = data[np.isfinite(data)]
            if num_bins is None:
                num_bins = np.sqrt(len(data))

            data_stats[column] = [
                np.nanmean(data),
                np.nanstd(data),
                np.nanmedian(data)
            ]

            if self.subplot:
                if use_prettyplotlib:
                    plt.hist(axes[x[i], y[i]], data, num_bins, grid="y")
                else:
                    axes[x[i], y[i]].hist(data, num_bins)
                axes[x[i], y[i]].set_xlabel(column)  # ADD UNITS!
            else:
                fig, axes = plt.subplots(1)
                axes.hist(data, num_bins)
                axes.set_xlabel(column)  # ADD UNITS!

            if self.verbose and not self.subplot:
                print column + " Stats: %s" % (data_stats[column])
                p.show()

            elif not self.subplot:
                fig.savefig(self.save_name + "_" + column + "." +
                            self.save_type)
                p.close()

        if self.subplot:
            p.tight_layout()
            if self.verbose:
                for column in self.columns:
                    print column + " Stats: %s" % (data_stats[column])
                p.show()
            else:
                fig.savefig(self.save_name + "_hists." + self.save_type)
Exemplo n.º 31
0
    def make_scatter(self, use_prettyplotlib=True, hists=True, num_bins=None):
        '''
        Plot two columns against each other. If self.subplot is enabled,
        all comparisons returned in a triangle collection. Inspiration for
        this form came from the package ![triangle.py](https://github.com/dfm/triangle.py).
        Small snippets to set the labels and figure size came from triangle.py.
        '''

        if use_prettyplotlib:
            try:
                import prettyplotlib as plt
            except ImportError:
                import matplotlib.pyplot as plt
                use_prettyplotlib = False
                print "prettyplotlib not installed. Using matplotlib..."
        else:
            import matplotlib.pyplot as plt

        # Setup subplots if plotting together
        if self.subplot:
            # Make the objects
            num = len(self.columns)
            factor = 2.0  # size of one side of one panel
            lbdim = 0.5 * factor  # size of left/bottom margin
            trdim = 0.3 * factor  # size of top/right margin
            whspace = 0.05  # w/hspace size
            plotdim = factor * num + factor * (num - 1.) * whspace
            dim = lbdim + plotdim + trdim
            fig, axes = plt.subplots(nrows=num, ncols=num, figsize=(dim, dim))

            lb = lbdim / dim
            tr = (lbdim + plotdim) / dim
            fig.subplots_adjust(left=lb,
                                bottom=lb,
                                right=tr,
                                top=tr,
                                wspace=whspace,
                                hspace=whspace)

        for i, column1 in enumerate(self.columns):
            for j, column2 in enumerate(self.columns):

                data1 = self.dataframe[column1]
                data2 = self.dataframe[column2]

                # Get rid of nans
                nans = np.isnan(data1) + np.isnan(data2)
                data1 = data1[~nans]
                data2 = data2[~nans]

                if self.subplot:
                    ax = axes[i, j]
                    if j > i:  # Don't bother plotting duplicates
                        ax.set_visible(False)
                        ax.set_frame_on(False)
                    else:

                        if j == i:  # Plot histograms
                            # Set number of bins
                            if num_bins is None:
                                num_bins = np.sqrt(len(data1))
                            if hists == True:
                                if use_prettyplotlib:
                                    plt.hist(ax, data1, num_bins, grid="y")
                                else:
                                    ax.hist(data1, num_bins)
                                    ax.grid(True)
                            else:
                                ax.set_visible(False)
                                ax.set_frame_on(False)

                            ax.set_xticklabels([])
                            ax.set_yticklabels([])

                        if j != i:
                            if use_prettyplotlib:
                                plt.scatter(ax, data2, data1)
                            else:
                                ax.scatter(data2, data1)
                            ax.grid(True)
                            ax.xaxis.set_major_locator(MaxNLocator(5))
                            ax.yaxis.set_major_locator(MaxNLocator(5))

                        if i < num - 1:
                            ax.set_xticklabels([])
                        else:
                            [l.set_rotation(45) for l in ax.get_xticklabels()]
                            ax.set_xlabel(column2)
                            ax.xaxis.set_label_coords(0.5, -0.3)

                        if j > 0:
                            ax.set_yticklabels([])
                        else:
                            [l.set_rotation(45) for l in ax.get_yticklabels()]
                            ax.set_ylabel(column1)
                            ax.yaxis.set_label_coords(-0.3, 0.5)

                else:
                    if j < i:
                        fig, axes = plt.subplots(1)
                        if use_prettyplotlib:
                            plt.scatter(axes, data2, data1, grid="y")
                        else:
                            axes.scatter(data2, data1)
                            axes.grid(True)
                        axes.set_xlabel(column2)  # ADD UNITS!
                        axes.set_ylabel(column1)  # ADD UNITS!

                        if self.verbose:
                            p.show()
                        else:
                            fig.savefig(self.save_name + "_" + column1 + "_" +
                                        column2 + "." + self.save_type)
                            p.close()

        if self.subplot:
            # p.tight_layout()
            if self.verbose:
                p.show()
            else:
                fig.savefig(self.save_name + "_" + "scatter" + "." +
                            self.save_type)
# <codecell>

print 'Ratio of Positive Tweets = %f'% (sum(res==1)/len(res))
print 'Ratio of Negative Tweets = %f'% (sum(res==0)/len(res))
print 'Ratio of Neutral Tweets = %f'% (sum(res==2)/len(res))

# <codecell>

#2eme verif
res_prob = predict(df, vectorizer, clf, proba = True)

# <codecell>

fig,ax = plt.subplots(1)
pplt.hist(ax,res_prob[:,1],bins=50)
plt.title('Distribution of Positive Probabilities')
plt.show()

# <codecell>

#3eme verif
df_res = pd.DataFrame({'date': df.date,'tweet': twits, 'positive': list(res_prob[:,1]), 'negative': list(res_prob[:,0]), 'neutral': list(res_prob[:,2])})
df_res = df_res.sort('positive',ascending=False)

# <codecell>

s = df_res.groupby('date').positive.mean()
fig, ax = plt.subplots(1)
pplt.plot(ax,x= s.index,y=s,linewidth=2)
plt.title('Sentiment of AAPL Stock - 01-Jan to 07-Nov 2013')
Exemplo n.º 33
0
import sys
import csv
import prettyplotlib as ppl
from prettyplotlib import plt
import numpy as np

blast_data = sys.argv[1].strip()

ident = []
with open(blast_data, "r") as handle:
    reader = csv.reader(handle)
    for row in reader:
        ident.append(float(row[2]))


fig, ax = plt.subplots(1)

ppl.hist(ax, ident)
plt.xlabel(u"Percentage of identity", fontdict={'fontsize':14})
plt.ylabel(u"Frecuency", fontdict={'fontsize':14})
ax.set_title("Plotted Blast results: % of identity")

fig.savefig('fig_blast_identity.png')
print "Made a plot of the percentags of identity from the blast data."
print "It is in the file `fig_blast_identity.png`"


    #AS WRITTEN
    #Stable
    #Open
    #Extro
    #Conci
    #Agree


# In[24]:


  #Histograms
import prettyplotlib as ppl
#for i in bfas.columns.values.tolist()[1:]:
    print i
    ppl.hist(bfas[i],bins=20)
    ppl.plt.savefig(i+'.png')
    ppl.plt.close()


# In[25]:


bfas.head()


# In[ ]:



Exemplo n.º 35
0
    def make_hists(self, num_bins=None, use_prettyplotlib=True):

        if use_prettyplotlib:
            try:
                import prettyplotlib as plt
            except ImportError:
                import matplotlib.pyplot as plt
                use_prettyplotlib = False
                print "prettyplotlib not installed. Using matplotlib..."
        else:
            import matplotlib.pyplot as plt

        # Setup subplots if plotting together
        if self.subplot:
          num = len(self.columns)
          if num <= 3:
            ncols = 1
            nrows = num
          elif num <= 8:
            ncols = 2
            nrows = num / 2
          else:  # Max columns right now is 12
            ncols = 3
            nrows = num / 3
          # Check if we need an extra row.
          if num % ncols != 0:
            nrows += 1

          # Make the objects
          fig, axes = plt.subplots(nrows=nrows, ncols=ncols)

          # This is a bit awkward to get the indices, but my matplotlib version
          # doesn't use the same object type as prettyplotlib creates.
          posns = np.indices(axes.shape)
          x, y = posns[0].ravel(), posns[1].ravel()

        # Keep the mean, median, std.
        data_stats = {}
        for i, column in enumerate(self.columns):
          data = self.dataframe[column]
          data = data[np.isfinite(data)]
          if num_bins is None:
            num_bins = np.sqrt(len(data))

          data_stats[column] = [nanmean(data), nanstd(data), nanmedian(data)]

          if self.subplot:
            if use_prettyplotlib:
              plt.hist(axes[x[i], y[i]],data, num_bins, grid="y")
            else:
              axes[x[i], y[i]].hist(data, num_bins)
            axes[x[i], y[i]].set_xlabel(column)  # ADD UNITS!
          else:
            fig, axes = plt.subplots(1)
            axes.hist(data, num_bins)
            axes.set_xlabel(column)  # ADD UNITS!

          if self.verbose and not self.subplot:
            print column+" Stats: %s" % (data_stats[column])
            p.show()

          elif not self.subplot:
            fig.savefig(self.save_name+"_"+column+"."+self.save_type)
            p.close()

        if self.subplot:
          p.tight_layout()
          if self.verbose:
            for column in self.columns:
              print column+" Stats: %s" % (data_stats[column])
            p.show()
          else:
            fig.savefig(self.save_name+"_hists."+self.save_type)
Exemplo n.º 36
0
def plot_qual_hist(quals, in_file):
    quals = [x for x in quals if x < 500.0]
    out_file = "%s-hist.png" % os.path.splitext(in_file)[0]
    fig, ax = plt.subplots(1)
    ppl.hist(ax, [quals], bins=100)
    fig.savefig(out_file)