Esempio n. 1
0
def hist_plot(thetali, qt, ql, zrange, krange, time_field, path):
    nk = len(krange)
    plt.figure(figsize=(25, 5))
    for k in range(nk):
        plt.subplot(1, nk, k + 1)
        plt.hist2d(thetali[k, :], qt[k, :], bins=100, normed=True)
        plt.colorbar()
        plt.title('z=' + str(zrange[k]) + 'm')
        plt.xlabel(r'$\theta_l$')
        plt.ylabel(r'$q_t$')
        # plt.xlim([298, 305])
        # plt.ylim([0.007,0.018])
    plt.suptitle('LES Data (t=' + str(np.round((time_field / 3600), 1)) + 'h)')
    plt.savefig(os.path.join(path, 'hist2d_plot_t' + str(time_field) + '.png'))
    plt.close()

    plt.figure(figsize=(25, 5))
    for k in range(nk):
        plt.subplot(1, nk, k + 1)
        plt.hist2d(thetali[k, :],
                   qt[k, :],
                   bins=100,
                   norm=LogNorm(),
                   normed=True)
        plt.colorbar()
        plt.title('z=' + str(zrange[k]) + 'm')
        plt.xlabel(r'$\theta_l$')
        plt.ylabel(r'$q_t$')
        # plt.xlim([298, 305])
        # plt.ylim([0.007,0.018])
    plt.suptitle('LES Data (t=' + str(np.round((time_field / 3600), 1)) + 'h)')
    plt.savefig(
        os.path.join(path, 'hist2d_plot_log_t' + str(time_field) + '.png'))
    plt.close()
    return
Esempio n. 2
0
def shear_plot2d(env, **kwargs):

    models = kwargs.pop('models', env.models)
    obj_index = kwargs.pop('obj_index', None)
    src_index = kwargs.pop('src_index', None)
    key = kwargs.pop('key', 'accepted')

    obj_slice = index_to_slice(obj_index)
    src_slice = index_to_slice(src_index)

    s0 = [[] for o in env.objects]
    s1 = [[] for o in env.objects]
    for mi, m in enumerate(models):
        # For H0 we only have to look at one model because the others are the same
        for oi, [obj, data] in enumerate(m['obj,data'][obj_slice]):
            if not data.has_key('shear'): continue
            #s0[oi].append(90-np.degrees(np.arctan2(*data['shear'])))
            s0[oi].append(data['shear'][0])
            s1[oi].append(data['shear'][1])

            #s0,s1 = data['shear']
            #Log( 'Model %i  Object %i  Shear %.4f %.4f' % (mi, oi, s0,s1) )

    kw = kwargs.copy()
    kw.setdefault(
        'bins',
        max(11,
            min(15, (int(np.sqrt(max(len(s0[0]), len(s1[0]))) // 2)) * 2 + 1)))
    if s0[0] and s1[0]:
        pl.hist2d(s0[0], s1[0], **kw)
        pl.title(r'Shear')
        pl.xlabel(r'$\varepsilon_1$')
        pl.ylabel(r'$\varepsilon_2$')
Esempio n. 3
0
def do_q2_sampling():
	NSAMPLES = 10000

	u = -1.0 + (2.0 * np.random.random(N))
	v = np.random.normal(0.0, 1.0)

	p.hist2d(u, v)
Esempio n. 4
0
def shear_plot2d(env, **kwargs):

    models = kwargs.pop('models', env.models)
    obj_index = kwargs.pop('obj_index', None)
    src_index = kwargs.pop('src_index', None)
    key = kwargs.pop('key', 'accepted')

    obj_slice = index_to_slice(obj_index)
    src_slice = index_to_slice(src_index)

    s0 = [ [] for o in env.objects ]
    s1 = [ [] for o in env.objects ]
    for mi,m in enumerate(models):
        # For H0 we only have to look at one model because the others are the same
        for oi, [obj,data] in enumerate(m['obj,data'][obj_slice]):
            if not data.has_key('shear'): continue
            #s0[oi].append(90-np.degrees(np.arctan2(*data['shear'])))
            s0[oi].append(data['shear'][0])
            s1[oi].append(data['shear'][1])

            #s0,s1 = data['shear']
            #Log( 'Model %i  Object %i  Shear %.4f %.4f' % (mi, oi, s0,s1) )

    kw = kwargs.copy()
    kw.setdefault('bins', max(11, min(15,(int(np.sqrt(max(len(s0[0]),len(s1[0])))//2)) * 2 + 1)))
    if s0[0] and s1[0]: 
        pl.hist2d(s0[0],s1[0], **kw)
        pl.title(r'Shear')
        pl.xlabel(r'$\varepsilon_1$')
        pl.ylabel(r'$\varepsilon_2$')
    def __init__(self, num, name, x_data, x_ax_label, x_nbins, y_data, y_ax_label, y_nbins, outputpath):

        plt.close('all')

        ## The histogram plot.
        plot = plt.figure(num, figsize=(5.0, 3.0), dpi=150, facecolor='w', edgecolor='w')

        # Adjust the position of the axes.
        plot.subplots_adjust(bottom=0.17, left=0.15)

        ## The plot axes.
        plotax = plot.add_subplot(111)

        # Set the y axis label.
        plt.ylabel(y_ax_label)

        # Set the x axis label.
        plt.xlabel(x_ax_label)

        # Add a grid.
        plt.grid(1)

        # Plot the 2D histogram.
        plt.hist2d(x_data, y_data, bins=[x_nbins, y_nbins], norm=LogNorm())

        # Add a colour bar.
        plt.colorbar()

        # Save the figure.
        plot.savefig("%s/%s.png" % (outputpath, name))
Esempio n. 6
0
def main(datafile, feature1, feature2, bins, percentile, copula, logscale):
    X, features = read_sah_h5(datafile, just_good=False)
    x = X[:, features.index(feature1)]
    y = X[:, features.index(feature2)]

    if percentile > 0 and not copula:
        bx = np.linspace(
            scoreatpercentile(x, percentile),
            scoreatpercentile(x, 100-percentile),
            bins)
        by = np.linspace(
            scoreatpercentile(y, percentile),
            scoreatpercentile(y, 100-percentile),
            bins)
        bins = (bx, by)

    if copula:
        x = copula_transform(x)
        y = copula_transform(y)

    if logscale:
        pl.hist2d(x, y, bins=bins, norm=LogNorm())
    else:
        pl.hist2d(x, y, bins=bins)
    pl.xlabel(feature1)
    pl.ylabel(feature2)
    pl.show()
Esempio n. 7
0
def draw5(x, y):

    from matplotlib.colors import LogNorm
    from pylab import hist2d, colorbar, show

    hist2d(x, y, bins=140, norm=LogNorm())
    colorbar()
    show()
Esempio n. 8
0
def plotgCAIsDomain(X,Y,xDiv=1,yDiv=20,figName=None):
    fig = pylab.figure(figsize=(320,3))
    pylab.hist2d(Y,X,bins=[len(np.unique(Y))/yDiv,xDiv], norm=mpl.colors.LogNorm(), cmap=mpl.cm.jet)
    pylab.xlabel("Domain Sorted By Translation Level")
    pylab.ylabel("gCAIs")
    pylab.title("Desity Plot - Domains Grouped by [%d], gCAIs Divided by [%d], Top [%d] Domains (PS : values in brackets are manipulable)"%(xDiv,yDiv,len(np.unique(Y))))
    fig.subplots_adjust(bottom=0.25)
    cbar = pylab.colorbar()
    if figName:
        pylab.savefig(figName)
    else:
        pylab.show()
    pylab.close(fig)
Esempio n. 9
0
def plotgCAIsDomain4(X,Y,xDiv=5,yDiv=25,figName=None):
    fig = pylab.figure(figsize=(200,5))
    pylab.hist2d(X,Y,bins=[max(X),yDiv], norm=mpl.colors.LogNorm(), cmap=mpl.cm.jet)
    pylab.xlabel("Expression Level")
    pylab.ylabel("gCAIs")
    pylab.title("Desity Plot - Expressoin Level Grouped by [%d], gCAIs Divided by [%d] (PS : values in brackets are manipulable)"%(xDiv,yDiv))
    pylab.xlim(0,5000)
    cbar = pylab.colorbar()
    if figName:
        pylab.savefig(figName)
    else:
        pylab.show()
    pylab.close(fig)
Esempio n. 10
0
def centroid_heatmap(c_samples, log_dir, x_min, x_max, y_min, y_max, bins=10):
    for i in range(np.shape(np.array(c_samples))[1]):
        cs = np.array(c_samples)[:, i, :]
        cx, cy = cs[:, 0], cs[:, 1]
        import matplotlib.colors as mcolors
        plt.figure(figsize=(5, 4))
        plt.hist2d(cx, cy, bins=bins, range=[[x_min, x_max], [y_min, y_max]])
        plt.xlabel('$x$-coordinate')
        plt.ylabel('$y$-coordinate')
        cbar = plt.colorbar()
        cbar.ax.set_ylabel('Number of samples')
        plt.savefig(log_dir + 'centroid_heat_' + str(i) + '.pdf',
                    bbox_inches='tight')
Esempio n. 11
0
def tVertexErrorHist2D(diffsList, values):
    """
    Plots a 2D error histogram for the tVertex-genVertex z values along some other axis,
    such as time smearing.
    Usage: tVertexErrorHist2D(differencesList)
    Differences are a 2D list of differences for each time smearing value.
    """
    pylab.hist2d(diffsList, values, bins=(100, len(np.unique(values))))
    pylab.xlabel("tVertexed $z$ - genVertex $z$ (mm)")
    pylab.ylabel("Smearing $\sigma$ (ps)")
    pylab.title("tVertexing Precision Over Time Smearing")
    cbar = pylab.colorbar()
    cbar.set_label("Counts (normalized per $\sigma$ value)")
    plt.show()
Esempio n. 12
0
def tVertexErrorHist2D(diffsList, values):
    '''
    Plots a 2D error histogram for the tVertex-genVertex z values along some other axis,
    such as time smearing.
    Usage: tVertexErrorHist2D(differencesList)
    Differences are a 2D list of differences for each time smearing value.
    '''
    pylab.hist2d(diffsList, values, bins=(100, len(np.unique(values))))
    pylab.xlabel("tVertexed $z$ - genVertex $z$ (mm)")
    pylab.ylabel("Smearing $\sigma$ (ps)")
    pylab.title("tVertexing Precision Over Time Smearing")
    cbar = pylab.colorbar()
    cbar.set_label("Counts (normalized per $\sigma$ value)")
    plt.show()
Esempio n. 13
0
def plot_responsability_2D_hist(
        file_name,
        save_img=False,
        output_file_name='responsability_histogram.png'):
    with h5py.File(file_name, 'r') as f:
        responsabilities = numpy.transpose(f['data'])
    max_o = []
    unique_rots = []
    for i in range(numpy.shape(responsabilities)[1]):
        max_o.append(max(responsabilities[:, i]))
        unique_rots.append(len(unique(responsabilities[:, i])))
    fig = pylab.figure('responsability histogram')
    pylab.hist2d(max_o, unique_rots, bins=100, norm=LogNorm())
    if save_img:
        pylab.savefig(output_file_name)
Esempio n. 14
0
def draw_testing_result(in_situ_SSM,
                        predicted_ssm,
                        rmse,
                        r,
                        save_path,
                        show_figure=0):
    plt.figure()
    # label of the axis.
    plt.xlabel(r'In-situ soil moisture [$cm^3/cm^3$]', fontsize=12)
    plt.ylabel(r'Estimated soil moisture [$cm^3/cm^3$]', fontsize=12)
    # plot the data with the density (number of pixels)
    h = hist2d(list(in_situ_SSM),
               list(predicted_ssm),
               bins=40,
               cmap='PuBu',
               range=[[0, 0.4], [0, 0.4]])
    cb = plt.colorbar()
    cb.set_label('Numbers of points')
    # Add 1:1 line
    x = np.arange(0, 0.4, 0.1, dtype=float)
    y = x
    # Add the information of RMSE and r on the figure.
    plt.text(0.1, 0.35, 'RMSE: %.2f' % rmse, fontdict={'size': 12})
    plt.text(0.1, 0.3, 'r: %.2f' % r, fontdict={'size': 12})
    plt.text(0.1, 0.25, 'Num: %d' % len(predicted_ssm), fontdict={'size': 12})

    plt.plot(x, y, color='black')
    plt.savefig(save_path, dpi=300)
    if show_figure == 0:
        plt.close()
Esempio n. 15
0
def plot_distribution_2d(data, xpar, ypar, percentiles=[16, 50, 84]):
   
   x, y = data[xpar], data[ypar]
   
   xpc  = np.percentile(x, percentiles, axis=0)
   ypc = np.percentile(y, percentiles, axis=0)
   
   pl.hist2d(x, y, bins=50, normed=True)
   
   for i in xpc:
      pl.axvline(x=i, ls='--', color='w')
   for i in ypc:
      pl.axhline(y=i, ls='--', color='w')
   
   pl.xlabel(xpar)
   pl.ylabel(ypar)
Esempio n. 16
0
    def do_hist2(self, s):
        print s
        el = self.get_this_command(s, min_args=2)

        datareduced = self.reduce_data(data, el[0], self.limits)

        if len(datareduced[0]) == 0:
            print "No Data"
            return

        arg_dict = {
            'bins': 25,
            'range': [[0.0, 30.0], [0.0, 30.0]],
            'normed': True
        }

        arg_dict.update(el[1])

        #if ’bins’ in el[1]:
        #     arg_dict['bins'] = int(el[1]['bins']

        #if ’normed’ in el[1]:
        #    arg_dict['normed'] = True

        #if 'log' in el[1]:
        #    arg_dict['norm'] = mc.LogNorm()

        pylab.hist2d(datareduced[0], datareduced[1], **arg_dict)

        #pylab.hist2d(datareduced[0], datareduced[1], bins=bins, normed=True, range=[[0.0,30.0],[0.0,30.0]])

        #bins = 25

        #        if len(el) > 1:
        #            bins = int(el[1])

        #if len(datareduced[0]):
        #    if len(el) > 2:
        #        if el[2].lower() == "log":
        #            pylab.hist2d(datareduced[0], datareduced[1], bins=bins, norm=mc.LogNorm())#, normed=True)
        #    else:
        #        pylab.hist2d(datareduced[0], datareduced[1], bins=bins, normed=True, range=[[0.0,30.0],[0.0,30.0]])

        pylab.colorbar()
        pylab.show(block=False)

        self.consume(s)
def main(datafile, feature1, feature2, clusterfile, clusterid,
         bins, percentile, copula, logscale):
    X, features = read_sah_h5(datafile, just_good=False)
    x = X[:, features.index(feature1)]
    y = X[:, features.index(feature2)]
    if 'id' in features:
        ids = X[:, features.index('id')]
    else:
        ids = np.arange(len(X)).astype(int)

    include = {}
    with open(clusterfile, 'r') as f:
        for line in f:
            i, c = map(float, line.strip().split(','))
            include[i] = (c == clusterid)

    include_mask = np.array([include.get(i, False) for i in ids])
    x = x[include_mask]
    y = y[include_mask]

    if percentile > 0 and not copula:
        bx = np.linspace(
            scoreatpercentile(x, percentile),
            scoreatpercentile(x, 100-percentile),
            bins)
        by = np.linspace(
            scoreatpercentile(y, percentile),
            scoreatpercentile(y, 100-percentile),
            bins)
        bins = (bx, by)

    if copula:
        x = copula_transform(x)
        y = copula_transform(y)

    if logscale:
        pl.hist2d(x, y, bins=bins, norm=LogNorm())
    else:
        pl.hist2d(x, y, bins=bins)
    pl.xlabel(feature1)
    pl.ylabel(feature2)
    pl.colorbar()
    pl.show()
Esempio n. 18
0
def Plot_Prof(med_log, bands, season, whata, whatb):

    for band in bands:
        idxb = med_log['band'] == band
        sel = med_log[idxb]
        """
        H, xedges, yedges = np.histogram2d(sel[whata],sel[whatb],bins=10,normed=True,range=[[np.min(sel[whata]),np.max(sel[whata])],[np.min(sel[whatb]),np.max(sel[whatb])]])
        print(xedges,yedges)
        """
        fig, ax = plt.subplots(ncols=1, nrows=1)
        fig.suptitle('Season ' + str(season) + ' - ' + band + ' band')
        plt.hist2d(sel[whata], sel[whatb], bins=20)
        plt.colorbar(fraction=0.02, pad=0.04)
        ax.set_xlabel(whata)
        ax.set_ylabel(whatb)
        #ax = fig.add_subplot(111)
        #im = plt.imshow(H, interpolation='nearest', origin='low',
        #               extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])
        """
Esempio n. 19
0
def draw4(x, y):

    from matplotlib.colors import LogNorm
    from pylab import hist2d, contour, grid, colorbar, show

    counts, ybins, xbins, image = hist2d(x, y, bins=100, norm=LogNorm())
    contour(counts, extent=[xbins.min(), xbins.max(), ybins.min(), ybins.max()], linewidths=10)
    grid(True)
    colorbar()
    show()
Esempio n. 20
0
    def plotD(self,PoI=None,DoW=None,ToD=None,uagent=None,nbins=500):
        parkc = self.all
        p_title = 'LA Parking Citation density'

        if DoW != None:
            if DoW == 'Weedays':
                p_title += ' during weekdays'
                parkc = parkc[(parkc.DoW != 'Saturday') & (parkc.DoW != 'Sunday')]
            elif DoW == 'Weekend':
                p_title+= ' during weekends'
                parkc = parkc[(parkc.DoW == 'Saturday') | (parkc.DoW == 'Sunday')]
            elif (DoW == 'Monday') | (DoW == 'Tuesday') | (DoW == 'Wednesday') | (DoW == 'Thursday') | (DoW == 'Friday') | (DoW == 'Saturday') | (DoW == 'Sunday'):
                parkc = parkc[parkc.DoW == DoW]
                p_title+= ' on '+DoW

        if ToD != None:
            if ToD == 'Early':
                p_title+= ' in the early morning'
                parkc = parkc[(parkc['Issue time'] >= 0) & (parkc['Issue time'] < 6)]
            elif ToD == 'Morning':
                p_title+= ' in the morning'
                parkc = parkc[(parkc['Issue time'] >= 6) & (parkc['Issue time'] < 12)]
            elif ToD == 'Afternoon':
                p_title+= ' in the afternoon'
                parkc = parkc[(parkc['Issue time'] >= 12) & (parkc['Issue time'] < 18)]
            elif ToD == 'Evening':
                p_title+= ' in the evening'
                parkc = parkc[(parkc['Issue time'] >= 18) & (parkc['Issue time'] < 24)]

        plt.hist2d(parkc.Longitude,parkc.Latitude,bins=nbins,norm=LogNorm())
        if type(PoI) == str:
            lon,lat = getLaLo(PoI,uagent=uagent)
            plt.plot(lon,lat,'r*',markersize=10)
        elif type(PoI) == list:
            plt.plot(PoI[0],PoI[1],'r*',markersize=10)
        plt.colorbar()
        plt.xlabel('Longitude')
        plt.ylabel('Latitude')
        plt.xlim([-118.7,-118.0])
        plt.ylim([33.7,34.4])
        plt.title(p_title)
        plt.show()
Esempio n. 21
0
def plot2DHist(points, name, x_dimension, y_dimension, fig):
  
  #add points to data at each corner, truncate data past corners.

  x = points[x_dimension]
  y = points[y_dimension]

  #truncate any data outside off -2,-2 2,2 borders
  index = []
  for i in range(0, len(x)):
    if x[i] > 2 or x[i] < -2:
      index = numpy.append(index, i)
    if y[i] > 2 or y[i] < -2:
      index = numpy.append(index, i)
  x = numpy.delete(x, index)
  y = numpy.delete(y, index)

  #fix borders of histogram with edge points
  x = numpy.append(x, -2)
  y = numpy.append(y, -2)
  x = numpy.append(x, -2)
  y = numpy.append(y, 2)
  x = numpy.append(x, 2)
  y = numpy.append(y, -2)
  x = numpy.append(x, 2)
  y = numpy.append(y, 2)

  #pylab.axis("off")
  
  #fig = pylab.figure()
  dpi = fig.get_dpi()
  inches = 512.0 / dpi
  fig.set_size_inches(inches,inches)
  
  ax = pylab.Axes(fig, [0., 0., 1., 1.])
  ax.set_axis_off()
  fig.add_axes(ax)
  pylab.hist2d(x, y, bins=100)
  pylab.set_cmap('gray')
  pylab.savefig(name + '.png')
  pylab.clf()
Esempio n. 22
0
def plot2DHist(points, name, x_dimension, y_dimension, fig):

    #add points to data at each corner, truncate data past corners.

    x = points[x_dimension]
    y = points[y_dimension]

    #truncate any data outside off -2,-2 2,2 borders
    index = []
    for i in range(0, len(x)):
        if x[i] > 2 or x[i] < -2:
            index = numpy.append(index, i)
        if y[i] > 2 or y[i] < -2:
            index = numpy.append(index, i)
    x = numpy.delete(x, index)
    y = numpy.delete(y, index)

    #fix borders of histogram with edge points
    x = numpy.append(x, -2)
    y = numpy.append(y, -2)
    x = numpy.append(x, -2)
    y = numpy.append(y, 2)
    x = numpy.append(x, 2)
    y = numpy.append(y, -2)
    x = numpy.append(x, 2)
    y = numpy.append(y, 2)

    #pylab.axis("off")

    #fig = pylab.figure()
    dpi = fig.get_dpi()
    inches = 512.0 / dpi
    fig.set_size_inches(inches, inches)

    ax = pylab.Axes(fig, [0., 0., 1., 1.])
    ax.set_axis_off()
    fig.add_axes(ax)
    pylab.hist2d(x, y, bins=100)
    pylab.set_cmap('gray')
    pylab.savefig(name + '.png')
    pylab.clf()
Esempio n. 23
0
def plot_hist2d(qt_, qt_env_tr, qt_up_tr, thetal_, th_env_tr, th_up_tr, ql_,
                ql_env_tr, ql_up_tr, n_tot, n_env_tr, n_up_tr, type_, z, t,
                path_, file_name):
    # (B) Figure with ql-coloring
    # ql_min = np.amin(ql_)
    # ql_max = np.amax(ql_)
    # x_min = np.amin(thetal_)
    # x_max = np.amax(thetal_)
    # y_min = np.amin(qt_)
    # y_max = np.amax(qt_)

    plt.figure(figsize=(12, 6))
    plt.subplot(1, 3, 1)
    plt.hist2d(
        thetal_, qt_
    )  #, c=ql_[:], s=5, alpha=0.5, edgecolors='none', vmin=ql_min, vmax=ql_max)  # , cmap = cm)
    labeling(r'$\theta_l$', r'$q_t$', x_min, x_max, y_min, y_max)
    plt.colorbar(shrink=0.75)
    plt.title('all data (n=' + str(n_tot) + ')')

    # plt.subplot(1, 3, 2)
    # plt.scatter(th_env_tr, qt_env_tr, c=ql_env_tr[:], s=5, alpha=0.5, edgecolors='none', vmin=ql_min,
    #             vmax=ql_max)  # , cmap = cm)
    # plt.colorbar(shrink=0.75)
    # labeling(r'$\theta_l$', r'$q_t$', x_min, x_max, y_min, y_max)
    # plt.title('environment (n=' + str(n_env_tr) + ')')
    #
    # plt.subplot(1, 3, 3)
    # plt.scatter(th_up_tr, qt_up_tr, c=ql_up_tr, s=5, alpha=0.5, edgecolors='none', vmin=ql_min, vmax=ql_max)  # , cmap = cm)
    # plt.colorbar(shrink=0.75)
    # labeling(r'$\theta_l$', r'$q_t$', x_min, x_max, y_min, y_max)
    # plt.title('updrafts (n=' + str(n_up_tr) + ')')
    #
    # plt.suptitle('Updraft selection ' + type_ + ' (z=' + str(z) + 'm, t=' + str(t) + ')')
    # print('save:', os.path.join(path_, file_name))
    # plt.savefig(os.path.join(path_, file_name))
    # plt.show()
    # print('saved')
    plt.close()
    return
Esempio n. 24
0
def draw_colourmap(densmap, quantity, xlims, ylims):
    """
    Draw a colour mesh map of a desired quantity for a given DataMap.

    """

    # Set quantity keyword
    for value, keyword in zip(['mass', 'number', 'temp', 'shear'], ['M', 'N', 'T', 'shear']):
        if quantity == value:
            _type = keyword

    # Initiate empty lists for cell values
    x = []; y = []; values = []

    # Get shape of system
    shape = datamap.cells.T.shape

    # With cells as a flat list, read values for position and quantity
    with DataMap.FlatArray(datamap.cells) as cells:
        for cell in cells:
            x.append(cell['X'])
            y.append(cell['Y'])
            values.append(cell[_type])

    # Draw quantity as 2D histogram for speed
    plt.hist2d(x, y, weights=values, bins=shape, vmin=args.Tmin, vmax=args.Tmax)#, xlim=xlims, ylim=ylims)
    plt.axis(args.axis)
    plt.xlim(xlims)
    plt.ylim(ylims)
    plt.colorbar()

    if save:
        plt.savefig(save, dpi=args.dpi)

    if args.show:
        plt.show()

    plt.clf()

    return None
Esempio n. 25
0
def main(datafile, feature1, feature2, clusterfile, clusterid, bins,
         percentile, copula, logscale):
    X, features = read_sah_h5(datafile, just_good=False)
    x = X[:, features.index(feature1)]
    y = X[:, features.index(feature2)]
    if 'id' in features:
        ids = X[:, features.index('id')]
    else:
        ids = np.arange(len(X)).astype(int)

    include = {}
    with open(clusterfile, 'r') as f:
        for line in f:
            i, c = map(float, line.strip().split(','))
            include[i] = (c == clusterid)

    include_mask = np.array([include.get(i, False) for i in ids])
    x = x[include_mask]
    y = y[include_mask]

    if percentile > 0 and not copula:
        bx = np.linspace(scoreatpercentile(x, percentile),
                         scoreatpercentile(x, 100 - percentile), bins)
        by = np.linspace(scoreatpercentile(y, percentile),
                         scoreatpercentile(y, 100 - percentile), bins)
        bins = (bx, by)

    if copula:
        x = copula_transform(x)
        y = copula_transform(y)

    if logscale:
        pl.hist2d(x, y, bins=bins, norm=LogNorm())
    else:
        pl.hist2d(x, y, bins=bins)
    pl.xlabel(feature1)
    pl.ylabel(feature2)
    pl.colorbar()
    pl.show()
Esempio n. 26
0
def main(datafile, feature1, feature2, bins, percentile, copula, logscale):
    X, features = read_sah_h5(datafile, just_good=False)
    x = X[:, features.index(feature1)]
    y = X[:, features.index(feature2)]

    if percentile > 0 and not copula:
        bx = np.linspace(scoreatpercentile(x, percentile),
                         scoreatpercentile(x, 100 - percentile), bins)
        by = np.linspace(scoreatpercentile(y, percentile),
                         scoreatpercentile(y, 100 - percentile), bins)
        bins = (bx, by)

    if copula:
        x = copula_transform(x)
        y = copula_transform(y)

    if logscale:
        pl.hist2d(x, y, bins=bins, norm=LogNorm())
    else:
        pl.hist2d(x, y, bins=bins)
    pl.xlabel(feature1)
    pl.ylabel(feature2)
    pl.show()
Esempio n. 27
0
    def __init__(self, num, name, x_data, x_ax_label, x_nbins, y_data,
                 y_ax_label, y_nbins, outputpath):
        """ Constructor. """

        plt.close('all')

        ## The histogram plot.
        plot = plt.figure(num,
                          figsize=(5.0, 3.0),
                          dpi=150,
                          facecolor='w',
                          edgecolor='w')

        # Adjust the position of the axes.
        plot.subplots_adjust(bottom=0.17, left=0.15)

        ## The plot axes.
        plotax = plot.add_subplot(111)

        # Set the y axis label.
        plt.ylabel(y_ax_label)

        # Set the x axis label.
        plt.xlabel(x_ax_label)

        # Add a grid.
        plt.grid(1)

        # Plot the 2D histogram.
        plt.hist2d(x_data, y_data, bins=[x_nbins, y_nbins], norm=LogNorm())

        # Add a colour bar.
        plt.colorbar()

        # Save the figure.
        plot.savefig("%s/%s.png" % (outputpath, name))
Esempio n. 28
0
    def pcr_poi(self,PoI,uagent=None,DoW=None,ToD=None,fmil=0.25,dyrs=4):
        lat_to_mi = 68.92
        lon_to_mi = 57.41
        p_title = 'Ave. parking citation rate, at PoI given'

        parkc = self.all

        if type(PoI) == str:
            lon,lat = getLaLo(PoI,uagent=uagent)
        elif type(PoI) == list:
            lon,lat = PoI[0], PoI[1]


        if DoW != None:
            if DoW == 'Weedays':
                p_title += ', during weekdays'
                parkc = parkc[(parkc.DoW != 'Saturday') & (parkc.DoW != 'Sunday')]
            elif DoW == 'Weekend':
                p_title+= ', during weekends'
                parkc = parkc[(parkc.DoW == 'Saturday') | (parkc.DoW == 'Sunday')]
            elif (DoW == 'Monday') | (DoW == 'Tuesday') | (DoW == 'Wednesday') | (DoW == 'Thursday') | (DoW == 'Friday') | (DoW == 'Saturday') | (DoW == 'Sunday'):
                parkc = parkc[parkc.DoW == DoW]
                p_title+= ', on '+DoW

        if ToD != None:
            if ToD == 'Early':
                p_title+= ', in the early morning'
                parkc = parkc[(parkc['Issue time'] >= 0) & (parkc['Issue time'] < 6)]
            elif ToD == 'Morning':
                p_title+= ', in the morning'
                parkc = parkc[(parkc['Issue time'] >= 6) & (parkc['Issue time'] < 12)]
            elif ToD == 'Afternoon':
                p_title+= ', in the afternoon'
                parkc = parkc[(parkc['Issue time'] >= 12) & (parkc['Issue time'] < 18)]
            elif ToD == 'Evening':
                p_title+= ', in the evening'
                parkc = parkc[(parkc['Issue time'] >= 18) & (parkc['Issue time'] < 24)]

        xbins = np.arange(np.min(parkc.Longitude),np.max(parkc.Longitude),fmil/lon_to_mi)
        ybins = np.arange(np.min(parkc.Latitude),np.max(parkc.Latitude),fmil/lat_to_mi)
        ahist,xbins,ybins,junk = plt.hist2d(parkc.Longitude,parkc.Latitude,bins=[xbins,ybins])
        plt.close()

        xdex = np.where([xbins < lon])[1][-1]
        ydex = np.where([ybins < lat])[1][-1]
        print(p_title+' : '+str(round(ahist[xdex,ydex]/(365.0*dyrs)/fmil**2,2))+' (per day/mil^2)')
        print('Largest rate: '+str(int(np.max(ahist)/(365.0*dyrs)/fmil**2)))
Esempio n. 29
0
 def plotAgainstGFP_hist2d(self):
     fig1 = pylab.figure(figsize = (20, 15))
     print len(self.GFP)
     for i in xrange(min(len(data.cat), 4)):
         print len(self.GFP[self.categories == i])
         vect = []
         pylab.subplot(2,2,i+1)
         pop = self.GFP[self.categories == i]
         print "cat", i, "n pop", len(self.GFP[(self.categories == i) & (self.GFP > -np.log(12.5))])
         H, xedges, yedges = np.histogram2d(self.angles[self.categories == i], self.GFP[self.categories == i], bins = 10)
         hist = pylab.hist2d(self.GFP[self.categories == i], self.angles[self.categories == i], bins = 10, cmap = pylab.cm.Reds, normed = True)
         pylab.clim(0.,0.035)
         pylab.colorbar()
         pylab.title(data.cat[i])
         pylab.xlabel('GFP score')
         pylab.ylabel('Angle (degree)')
         pylab.xlim([-4.2, -1])
     pylab.show()
Esempio n. 30
0
pl.plot(prediction_error_history)
pl.title("Prediction Error History")
pl.xlabel("time")
pl.ylabel("Prediction Error")
save_figure.save(folder_name+"/Prediction Error History")

pl.figure(expert.cluster_num+2)
pl.hist(state1_history)
pl.title("Resultant State Histogram")
pl.xlabel("State")
pl.ylabel("# of Occurrence")
pl.autoscale(True)
save_figure.save(folder_name+"/Resultant State Histogram")

pl.figure(expert.cluster_num+3)
pl.hist2d(state0_history, action0_history)
pl.title("Initial State vs Initial Action Histogram")
pl.xlabel("State")
pl.ylabel("Action")
pl.colorbar()
save_figure.save(folder_name+"/Initial State vs Initial Action Histogram")

#print("Most common Action")
def most_common(lst):
    return max(set(lst), key=lst.count)
bin_num = 100
bin_size = int(len(action0_history)/bin_num)
most_common_action = []
for i in range(bin_num):
    start = i*bin_size
    end = start + bin_size
Esempio n. 31
0
    def plot(self, bins=100, cmap="hot_r", fontsize=10, Nlevels=4,
        xlabel=None, ylabel=None, norm=None, range=None, normed=False,
        colorbar=True, contour=True, grid=True, **kargs):
        """plots histogram of mean across replicates versus coefficient variation

        :param int bins: binning for the 2D histogram (either a float or list 
            of 2 binning values).
        :param cmap: a valid colormap (defaults to hot_r)
        :param fontsize: fontsize for the labels
        :param int Nlevels: must be more than 2
        :param str xlabel: set the xlabel (overwrites content of the dataframe)
        :param str ylabel: set the ylabel (overwrites content of the dataframe)
        :param norm: set to 'log' to show the log10 of the values.
        :param normed: normalise the data
        :param range: as in pylab.Hist2D : a 2x2 shape [[-3,3],[-4,4]]
        :param contour: show some contours (default to True)
        :param bool grid: Show unerlying grid (defaults to True)

        If the input is a dataframe, the xlabel and ylabel will be populated
        with the column names of the dataframe.

        """
        X = self.df[self.df.columns[0]].values
        Y = self.df[self.df.columns[1]].values
        if len(X) > 10000:
            print("Computing 2D histogram. Please wait")

        pylab.clf()
        if norm == 'log':
            from matplotlib import colors
            res = pylab.hist2d(X, Y, bins=bins, normed=normed,
               cmap=cmap, norm=colors.LogNorm())
        else:
            res = pylab.hist2d(X, Y, bins=bins, cmap=cmap, 
                    normed=normed, range=range)

        if colorbar is True:
            pylab.colorbar()

        if contour:
            try:
                bins1 = bins[0]
                bins2 = bins[1]
            except:
                bins1 = bins
                bins2 = bins

            X, Y = pylab.meshgrid(res[1][0:bins1], res[2][0:bins2])
            if contour:
                if res[0].max().max() < 10 and norm == 'log':
                    pylab.contour(X, Y, res[0].transpose(),  color="g")
                else:
                    levels = [round(x) for x in 
                            pylab.logspace(0, pylab.log10(res[0].max().max()), Nlevels)]
                    pylab.contour(X, Y, res[0].transpose(), levels[2:], color="g")
                #pylab.clabel(C, fontsize=fontsize, inline=1)

        if ylabel is None:
            ylabel = self.df.columns[1]
        if xlabel is None:
            xlabel = self.df.columns[0]

        pylab.xlabel(xlabel, fontsize=fontsize)
        pylab.ylabel(ylabel, fontsize=fontsize)

        if grid is True:
            pylab.grid(True)

        return res
def corner(samples, labels):
    N = len(labels)
    from matplotlib.colors import LogNorm

    py.figure(figsize=(12, 12))

    axes = {}
    for i, l1 in enumerate(labels):
        for j, l2 in enumerate(labels):
            if j > i:
                continue

            ax = py.subplot2grid((N, N), (i, j))
            axes[(i, j)] = ax

            idx_y = labels.index(l1)
            idx_x = labels.index(l2)
            x, y = samples[:, idx_x], samples[:, idx_y]

            if i == j:
                # plot distributions
                xx, yy = histogram(x, bins=200, plot=False)
                py.plot(xx, yy, '-o', markersize=3)
                py.gca().set_yticklabels([])

                if i == (N - 1):
                    py.xlabel(l2)
                    [l.set_rotation(45) for l in ax.get_xticklabels()]
                else:
                    ax.set_xticklabels([])

            else:
                counts, ybins, xbins, image = py.hist2d(x,
                                                        y,
                                                        bins=100,
                                                        norm=LogNorm())
                #py.contour(counts,extent=[xbins.min(),xbins.max(),ybins.min(),ybins.max()],linewidths=3)

                if i == (N - 1):
                    py.xlabel(l2)
                    [l.set_rotation(45) for l in ax.get_xticklabels()]
                else:
                    ax.set_xticklabels([])

                if j == 0:
                    py.ylabel(l1)
                    [l.set_rotation(45) for l in ax.get_yticklabels()]
                else:
                    ax.set_yticklabels([])

    # make all the x- and y-lims the same
    j = 0
    lims = [0] * N
    for i in range(1, N):
        ax = axes[(i, 0)]
        lims[i] = ax.get_ylim()

        if i == N - 1:
            lims[0] = ax.get_xlim()

    for i, l1 in enumerate(labels):
        for j, l2 in enumerate(labels):
            if j > i:
                continue

            ax = axes[(i, j)]

            if j == i:
                ax.set_xlim(lims[i])
            else:
                ax.set_ylim(lims[i])
                ax.set_xlim(lims[j])
Esempio n. 33
0
df = df[df["Primary Type"].isin(["ROBBERY","ASSAULT","BATTERY"])]
df = df[df["Location Description"].isin(["STREET","SIDEWALK","ALLEY"])]

hours = [datetime.strptime(timestr,"%m/%d/%Y %I:%M:%S %p").hour for timestr in list(df.Date)]

df["hour"] = hours

for i in range(24):
	df1 = df[df.hour==i]
	
	plt.figure(figsize=(6, 5), dpi=80, facecolor='w', edgecolor='k')
	
	y = list(df1["Latitude"])
	x = list(df1["Longitude"])
	
	plt.hist2d(x, y, bins=100, vmax=35,range=np.array([(xmin, xmax), (ymin, ymax)]))
	
	#plt.title("Robbery, assualt, and battery\n on streets, sidewalks, and alleys")
	plt.text(-87.95,41.65,"Hour: "+str(i),color="white")
	plt.xlim([xmin,xmax])
	plt.ylim([ymin,ymax])
	plt.xlabel("Latitude")
	plt.ylabel("Longtitude")
	plt.xticks([])
	plt.yticks([])
	plt.colorbar()
	
	plt.axes().set_aspect('equal')
	
#	plt.show()
	plt.savefig(str(i)+".gif")
Esempio n. 34
0
def main():
    #Set font size
    font = {'size': 28}

    matplotlib.rc('font', **font)

    signalNames = [
        "WR800N200", "WR800N400", "WR800N600", "WR800N700", "WR1000N200",
        "WR1000N400", "WR1000N600", "WR1000N800", "WR1000N900", "WR1200N400",
        "WR1200N600", "WR1200N800", "WR1200N1000", "WR1200N1100", "WR1400N400",
        "WR1400N600", "WR1400N800", "WR1400N1000", "WR1400N1200",
        "WR1400N1300", "WR1600N400", "WR1600N600", "WR1600N800", "WR1600N1000",
        "WR1600N1200", "WR1600N1400", "WR1600N1500", "WR1800N400",
        "WR1800N600", "WR1800N800", "WR1800N1000", "WR1800N1200",
        "WR1800N1400", "WR1800N1600", "WR1800N1700", "WR2000N600",
        "WR2000N800", "WR2000N1000", "WR2000N1200", "WR2000N1400",
        "WR2000N1600", "WR2000N1800", "WR2000N1900"
    ]

    #Load background files
    dy = np.load("DY.npy")
    ttbar = np.load("ttbar.npy")

    #Modify colormap to be white at 0
    viridis = cm.get_cmap('viridis', 256)
    newcolors = viridis(np.linspace(0, 1, 256))
    white = np.array([256 / 256, 256 / 256, 256 / 256, 1])
    newcolors[:1, :] = white
    cmap = ListedColormap(newcolors)

    resolvedNdy = []
    superResolvedNdy = []
    leadNdy = []
    subleadNdy = []
    WRdy = []
    weightdy = []

    resolvedNttbar = []
    superResolvedNttbar = []
    leadNttbar = []
    subleadNttbar = []
    WRttbar = []
    weightttbar = []

    #Extract ttbar background
    for x in range(len(ttbar)):
        resolvedNttbar.append(ttbar[x][2])
        superResolvedNttbar.append(ttbar[x][1])
        WRttbar.append(ttbar[x][0])
        leadNttbar.append(ttbar[x][5])
        subleadNttbar.append(ttbar[x][6])
        weightttbar.append(ttbar[x][-1] * 1000.0 * 35.9)

    #Extract dy backgorund
    for x in range(len(dy)):
        resolvedNdy.append(dy[x][2])
        superResolvedNdy.append(dy[x][1])
        WRdy.append(dy[x][0])
        leadNdy.append(dy[x][5])
        subleadNdy.append(dy[x][6])
        weightdy.append(dy[x][-1] * 1000.0 * 35.9)
    resolvedN = resolvedNttbar + resolvedNdy
    superResolvedN = superResolvedNttbar + superResolvedNdy
    leadN = leadNttbar + leadNdy
    subleadN = subleadNttbar + subleadNdy
    WR = WRttbar + WRdy
    weight = weightttbar + weightdy
    #Iterate over the signal samples
    for y in range(len(signalNames)):
        signal = np.load(signalNames[y] + ".npy")

        resolvedN2 = []
        superResolvedN2 = []
        leadN2 = []
        subleadN2 = []
        WR2 = []
        weight2 = []
        for x in range(len(signal)):
            resolvedN2.append(signal[x][2])
            superResolvedN2.append(signal[x][1])
            WR2.append(signal[x][0])
            leadN2.append(signal[x][5])
            subleadN2.append(signal[x][6])
            weight2.append(signal[x][-1] * 1000.0 * 35.9)

        fSizeX = 13.5
        fSizeY = 9
        xMax = 4000

        #Generate plots
        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist(np.array(WR2),
                 weights=np.array(weight2),
                 bins=100,
                 range=(0, 3000))
        plt.title("WR signal")
        plt.xlabel("m_lljj (GeV)")
        plt.savefig("signalBackground2/" + signalNames[y] + "/WR_signal.png")
        plt.show()

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist2d(np.array(resolvedN2),
                   np.array(WR2),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, 2500], [0, 3000]],
                   cmap=cmap)
        plt.title("NN Resolved Leptons signal")
        plt.ylabel("m_lljj (GeV)")
        plt.xlabel("m_ljj (GeV)")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_Resolved_Leptons_signal.png")
        plt.show()

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist2d(np.array(superResolvedN2),
                   np.array(WR2),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, 2500], [0, 3000]],
                   cmap=cmap)
        plt.title("NN Super Resolved Leptons signal")
        plt.ylabel("m_lljj (GeV)")
        plt.xlabel("m_ljj (GeV)")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_SuperResolved_Leptons_signal.png")
        plt.show()

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist2d(np.array(resolvedN2),
                   np.array(WR2) - np.array(resolvedN2),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, xMax], [0, 3000]],
                   cmap=cmap)
        plt.title("NN Resolved Leptons signal shifted part 1")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_Resolved_Leptons_signal_shift_p1.png")
        plt.show()

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist2d(np.array(superResolvedN2),
                   np.array(WR2) - np.array(superResolvedN2),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, xMax], [0, 3000]],
                   cmap=cmap)
        plt.title("NN Super Resolved Leptons signal shifted part 1")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_SuperResolved_Leptons_signal_shift_p1.png")
        plt.show()

        plt.figure(figsize=(fSizeX, fSizeY))
        plt.hist2d(np.array(resolvedN2),
                   np.log10(np.array(WR2) - np.array(resolvedN2)),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, xMax], [1, 5]],
                   cmap=cmap)
        plt.title("NN Resolved Leptons signal shifted full\n")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_Resolved_Leptons_signal_shift.png")
        plt.show()

        plt.figure(figsize=(fSizeX, fSizeY))
        plt.hist2d(np.array(superResolvedN2),
                   np.log10(np.array(WR2) - np.array(superResolvedN2)),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, xMax], [1, 5]],
                   cmap=cmap)
        plt.title("NN Super Resolved Leptons signal shifted full\n")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_SuperResolved_Leptons_signal_shift.png")
        plt.show()

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist([np.array(WRttbar), np.array(WRdy)],
                 weights=[np.array(weightttbar),
                          np.array(weightdy)],
                 bins=100,
                 range=(0, 3000),
                 stacked=True,
                 label=["ttbar", "dy"])
        plt.title("WR background")
        plt.xlabel("m_lljj (GeV)")
        plt.legend()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/WR_background.png")
        plt.show()

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist2d(np.array(resolvedN),
                   np.array(WR),
                   weights=np.array(weight),
                   bins=[100, 100],
                   range=[[0, 2500], [0, 3000]],
                   cmap=cmap)
        plt.title("NN Resolved Leptons background")
        plt.ylabel("m_lljj (GeV)")
        plt.xlabel("m_ljj (GeV)")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_Resolved_Leptons_background.png")
        plt.show()

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist2d(np.array(superResolvedN),
                   np.array(WR),
                   weights=np.array(weight),
                   bins=[100, 100],
                   range=[[0, 2500], [0, 3000]],
                   cmap=cmap)
        plt.title("NN Super Resolved Leptons background")
        plt.ylabel("m_lljj (GeV)")
        plt.xlabel("m_ljj (GeV)")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_SuperResolved_Leptons_background.png")
        plt.show()

        plt.figure(figsize=(fSizeX, fSizeY))
        plt.hist2d(np.array(resolvedN),
                   np.log10(np.array(WR) - np.array(resolvedN)),
                   weights=np.array(weight),
                   bins=[100, 100],
                   range=[[0, xMax], [1, 5]],
                   cmap=cmap)
        plt.title("NN Resolved Leptons background")
        plt.ylabel("m_lljj (GeV)")
        plt.xlabel("m_ljj (GeV)")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_Resolved_Leptons_background_shift.png")
        plt.show()

        plt.figure(figsize=(fSizeX, fSizeY))
        plt.hist2d(np.array(superResolvedN),
                   np.log10(np.array(WR) - np.array(superResolvedN)),
                   weights=np.array(weight),
                   bins=[100, 100],
                   range=[[0, xMax], [1, 5]],
                   cmap=cmap)
        plt.title("NN Super Resolved Leptons background")
        plt.ylabel("m_lljj (GeV)")
        plt.xlabel("m_ljj (GeV)")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_SuperResolved_Leptons_background_shift.png")
        plt.show()

        fSizeX = 13.5
        fSizeY = 9
        xMax = 4000

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist(
            [np.array(WRttbar),
             np.array(WRdy), np.array(WR2)],
            weights=[
                np.array(weightttbar),
                np.array(weightdy),
                np.array(weight2)
            ],
            bins=100,
            range=(0, 3000),
            stacked=True,
            label=["ttbar", "dy", "signal"])
        plt.title("WR signal + background")
        plt.xlabel("m_lljj (GeV)")
        plt.legend()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/WR_signal_plus_background.png")
        plt.show()

        resolvedN2 += resolvedN
        superResolvedN2 += superResolvedN
        leadN2 += leadN
        subleadN2 += subleadN
        WR2 += WR
        weight2 += weight

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist2d(np.array(resolvedN2),
                   np.array(WR2),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, 2500], [0, 3000]],
                   cmap=cmap)
        plt.title("NN Resolved Leptons combined")
        plt.ylabel("m_lljj (GeV)")
        plt.xlabel("m_ljj (GeV)")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_Resolved_Leptons_combined.png")
        plt.show()

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist2d(np.array(superResolvedN2),
                   np.array(WR2),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, 2500], [0, 3000]],
                   cmap=cmap)
        plt.title("NN Super Resolved Leptons combined")
        plt.ylabel("m_lljj (GeV)")
        plt.xlabel("m_ljj (GeV)")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_SuperResolved_Leptons_combined.png")
        plt.show()

        plt.figure(figsize=(fSizeX, fSizeY))
        plt.hist2d(np.array(resolvedN2),
                   np.log10(np.array(WR2) - np.array(resolvedN2)),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, xMax], [1, 5]],
                   cmap=cmap)
        plt.title("NN Resolved Leptons combined shifted\n")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_Resolved_Leptons_combined_shift.png")
        plt.show()

        plt.figure(figsize=(fSizeX, fSizeY))
        plt.hist2d(np.array(superResolvedN2),
                   np.log10(np.array(WR2) - np.array(superResolvedN2)),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, xMax], [1, 5]],
                   cmap=cmap)
        plt.title("NN Super Resolved Leptons combined shifted\n")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/NN_SuperResolved_Leptons_combined_shift.png")
        plt.show()

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist2d(np.array(leadN2),
                   np.array(WR2),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, 2500], [0, 3000]],
                   cmap=cmap)
        plt.title("Lead Leptons combined")
        plt.ylabel("m_lljj (GeV)")
        plt.xlabel("m_ljj (GeV)")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/Lead_Leptons_combined.png")
        plt.show()

        plt.figure(figsize=(fSizeY * 2, fSizeY))
        plt.hist2d(np.array(subleadN2),
                   np.array(WR2),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, 2500], [0, 3000]],
                   cmap=cmap)
        plt.title("Sublead Leptons combined")
        plt.ylabel("m_lljj (GeV)")
        plt.xlabel("m_ljj (GeV)")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/Sublead_Leptons_combined.png")
        plt.show()

        plt.figure(figsize=(fSizeX, fSizeY))
        plt.hist2d(np.array(leadN2),
                   np.log10(np.array(WR2) - np.array(leadN2)),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, xMax], [1, 5]],
                   cmap=cmap)
        plt.title("Lead Leptons combined shifted")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/Lead_Leptons_combined_shift.png")
        plt.show()

        plt.figure(figsize=(fSizeX, fSizeY))
        plt.hist2d(np.array(subleadN2),
                   np.log10(np.array(WR2) - np.array(subleadN2)),
                   weights=np.array(weight2),
                   bins=[100, 100],
                   range=[[0, xMax], [1, 5]],
                   cmap=cmap)
        plt.title("Sublead Leptons combined shifted")
        plt.colorbar()
        plt.savefig("signalBackground2/" + signalNames[y] +
                    "/Sublead_Leptons_combined_shift.png")
        plt.show()
Esempio n. 35
0
        if plot_1 == True:
            hist_fig = pylab.figure()
            x = energies
            if weight_by_p_earth == True:
                hist_fig.suptitle(
                    'Trigger = %0.1f (Weighted by $p_\mathrm{earth}$' %
                    trigger_level)
            else:
                hist_fig.suptitle('Trigger = %0.1f' % trigger_level)

            ax1 = pylab.subplot(2, 3, 1)

            pylab.hist2d(x,
                         info['observation_angle'],
                         bins=bins,
                         weights=w1,
                         norm=LogNorm())
            pylab.ylabel('Observation Angle (deg)')
            pylab.xlabel('E (GeV)')
            pylab.colorbar()

            pylab.subplot(2, 3, 4, sharex=ax1, sharey=ax1)

            pylab.hist2d(x,
                         info['observation_angle'],
                         bins=bins,
                         weights=w2,
                         norm=LogNorm())
            pylab.ylabel('Observation Angle (deg)')
            pylab.xlabel(
Esempio n. 36
0
            pl.xticks([])
            pl.yticks([])
        pl.suptitle(str(cube_sizeX) + ' x ' + str(cube_sizeY) + ' slices comparison')
            
            
        
        
        
        
        # Plot the 2D histograms
            
        pl.figure()
        prediction = predicted_distances[cube_slice].flatten()
        results = out.flatten()
        labels = true_distances[cube_slice].flatten()
        pl.subplot(1,2,1)
        pl.hist2d(labels, prediction, (max_dist+1, max_dist+1), cmap=pl.cm.jet, norm=pl.mpl.colors.LogNorm())
        pl.xlabel('ground truth')
        pl.ylabel('noisy distance map')
        pl.title('2d histogram of noisy distance')
        
        pl.subplot(1,2,2)
        pl.hist2d(labels, results, (15, 15), cmap=pl.cm.jet, norm=pl.mpl.colors.LogNorm())
        pl.xlabel('ground truth')
        pl.ylabel('smoothed distance map')
        pl.title('2d histogram of smoothed distance')
        pl.show()
        
                
        
Esempio n. 37
0
#####################e
# Some MC Plot to see what Energy We have
#####################e
#max_nrg_mc = ev_df.p_mc_mag.max()
#n, bins, patches = plt.hist(ev_df.p_mc_mag,bins=15,facecolor='blue',alpha = 0.8)
#plt.title('Shower Energy')
#n, bins, patches = plt.hist(ev_df.p_mc_mag,bins=max_nrg_mc,range=(0,max_nrg_mc),facecolor='red',alpha = 0.8)
#plt.show()

# Let's compare the totall charge deposited wrt all charge clustered
# Pre - factor fit
t = np.arange(0., 100000000, 1000)
plt.hist2d(ev_df.mc_qdep,
           ev_df.q_tot_obj,
           bins=100,
           range=[[0, 100000000], [0, 100000000]],
           cmap='gnuplot2',
           norm=LogNorm())
plt.plot(t, t, 'k', label='y=x')
plt.plot(t, 2 * t, 'r-', label='y=2x')
plt.legend(loc='upper left')
plt.title("Reco_Charge vs MC_charge")
plt.xlabel("mc_q (e)")
plt.ylabel("reco_q(e)")
if _save:
    plt.savefig('{}/recovmccharge.png'.format(fig_dir))
plt.show()
plt.close()

n, bins, patches = plt.hist((ev_df.mc_qdep - ev_df.q_tot_obj) / ev_df.mc_qdep,
                            bins=60,
Esempio n. 38
0
def plot_PDF(data, x_, y_, z_, ZZ, var_name1, var_name2, var_name3, score, amp_qt, amp_w, z):
    fig = plt.figure(figsize=(20, 15))

    plt.subplot(3, 5, 1)
    plt.scatter(data[:, 0], data[:, 1], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.subplot(3, 5, 2)
    ax1 = plt.hist2d(data[:, 0], data[:, 1], bins=30, normed=True)
    plt.colorbar(shrink=0.8)
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.title('data histogram')
    plt.subplot(3, 5, 3)
    # xxx
    ax1 = plt.contourf(x_, y_, np.sum(np.exp(ZZ),axis=2).T)
    # xxx
    # plt.text(0.1, 0.9, 'score='+str(score), ha='center', va='center')#, transform=ax.transAxes)
    # text(x, y, s, fontdict=None, withdash=False, **kwargs)
    # plt.text(1, 1, 'HOIHOI',color='r')
    plt.colorbar(ax1, shrink=0.8)
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.subplot(3, 5, 4)
    ax1 = plt.hist2d(data[:, 0], data[:, 1], bins=30, normed=True)
    # xxx
    ax2 = plt.contour(x_, y_, np.sum(np.exp(ZZ), axis=2).T, colors='w', linewidths=2)
    plt.colorbar(ax2, shrink=0.8)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name2, amp_qt, amp_w)


    plt.subplot(3, 5, 6)
    plt.scatter(data[:, 0], data[:, 2], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 7)
    ax1 = plt.hist2d(data[:, 0], data[:, 2], bins=30, normed=True)
    plt.colorbar(shrink=0.8)
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.title('data histogram')
    plt.subplot(3, 5, 8)
    # xxx
    ax1 = plt.contourf(x_, z_, np.sum(np.exp(ZZ), axis=1).T)
    # xxx
    plt.colorbar(ax1, shrink=0.8)
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 9)
    ax1 = plt.hist2d(data[:,0], data[:, 2], bins=30, normed=True)
    # xxx
    ax2 = plt.contour(x_, z_ , np.sum(np.exp(ZZ), axis=1).T, colors='w', linewidths=2)
    plt.colorbar(ax2, shrink=0.8)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name3, amp_qt, amp_w)

    plt.subplot(3, 5, 11)
    plt.scatter(data[:, 1], data[:, 2], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 12)
    ax1 = plt.hist2d(data[:, 1], data[:, 2], bins=30, normed=True)
    plt.colorbar(shrink=0.8)
    plt.title('data histogram')
    plt.subplot(3, 5, 13)
    # xxx
    ax1 = plt.contourf(y_, z_, np.sum(np.exp(ZZ), axis=0).T)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    plt.colorbar(ax1, shrink=0.8)
    plt.subplot(3, 5, 14)
    ax1 = plt.hist2d(data[:,1], data[:,2], bins=30, normed=True)
    # xxx
    ax2 = plt.contour(y_, z_, np.sum(np.exp(ZZ), axis=0).T, colors='w', linewidths=2)
    plt.colorbar(ax2, shrink=0.8)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    # plt.colorbar(ax1, shrink=0.8)

    fig.suptitle('EM2 PDF: ' + var_name1 + var_name2 + var_name3 + ' (score='+str(score)+'; z=' + str(z) +'m)', fontsize=20)
    plt.savefig(os.path.join(
        fullpath_out,'EM2_trivar_alltimes_figures','EM2_PDF_trivariate_' + var_name1 + var_name2 + var_name3 + '_z' + str(
            np.int(z)) + 'm.png')
    )

    plt.close()

    return
Esempio n. 39
0
#z reki
#pliki=["ot001", "ot002", "ot009", "ot019", "ot020" , "nt001"]; 





bin_width = 0.01;
rec = root2rec(sys.argv[1], "tdig")
       
#x = np.extract(np.absolute(rec.Teta) < 1.61, rec.Tbeta)
#x = np.extract(np.logical_and(np.logical_and(np.absolute(rec.Teta0) < 1.61, rec.Tlbx_1), rec.Tpt0 > 10), rec.Teta0);
#y = np.extract(np.logical_and(np.logical_and(np.absolute(rec.Teta0) < 1.61, rec.Tlbx_1), rec.Tpt0 > 10), rec.Tphi0);

for i in range(0, len(rec)):
    print i
'''
print  len(x), len(y)

pl.hist2d(x, y, bins=200, norm=LogNorm())
#pl.hist2d(x, y, bins=np.arange(0.,4,bin_width) , norm=LogNorm())
pl.colorbar()
#plt.xscale('log')
plt.ylabel(r'$\phi$')
plt.xlabel(r'$\eta$')
plt.draw()
pp.savefig()
pp.close()
plt.show()
'''
Esempio n. 40
0
def plot_PDF(data, x_, y_, z_, ZZ, var_name1, var_name2, var_name3, amp_qt,
             amp_w, time, z):
    fig = plt.figure(figsize=(18, 15))

    plt.subplot(3, 5, 1)
    plt.scatter(data[:, 0], data[:, 1], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.subplot(3, 5, 2)
    ax1 = plt.hist2d(data[:, 0], data[:, 1], bins=30, normed=True)
    plt.colorbar(shrink=0.8)
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.title('data histogram')
    plt.subplot(3, 5, 3)
    # xxx
    ax1 = plt.contourf(x_, y_, np.sum(np.exp(ZZ), axis=2).T)
    # xxx
    plt.colorbar(ax1, shrink=0.8)
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.subplot(3, 5, 4)
    ax1 = plt.hist2d(data[:, 0], data[:, 1], bins=30, normed=True)
    # xxx
    ax2 = plt.contour(x_,
                      y_,
                      np.sum(np.exp(ZZ), axis=2).T,
                      colors='w',
                      linewidths=2)
    # xxx
    plt.colorbar(ax2, shrink=0.8)
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name2, amp_qt, amp_w)

    plt.subplot(3, 5, 6)
    plt.scatter(data[:, 0], data[:, 2], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 7)
    ax1 = plt.hist2d(data[:, 0], data[:, 2], bins=30, normed=True)
    plt.colorbar(shrink=0.8)
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.title('data histogram')
    plt.subplot(3, 5, 8)
    # xxx
    ax1 = plt.contourf(x_, z_, np.sum(np.exp(ZZ), axis=1).T)
    # xxx
    plt.colorbar(ax1, shrink=0.8)
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 9)
    ax1 = plt.hist2d(data[:, 0], data[:, 2], bins=30, normed=True)
    # xxx
    ax2 = plt.contour(x_,
                      z_,
                      np.sum(np.exp(ZZ), axis=1).T,
                      colors='w',
                      linewidths=2)
    # xxx
    plt.colorbar(ax2, shrink=0.8)
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name3, amp_qt, amp_w)

    plt.subplot(3, 5, 11)
    plt.scatter(data[:, 1], data[:, 2], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 12)
    ax1 = plt.hist2d(data[:, 1], data[:, 2], bins=30, normed=True)
    plt.colorbar(shrink=0.8)
    plt.title('data histogram')
    plt.subplot(3, 5, 13)
    # xxx
    ax1 = plt.contourf(y_, z_, np.sum(np.exp(ZZ), axis=0).T)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    plt.colorbar(ax1, shrink=0.8)
    plt.subplot(3, 5, 14)
    ax1 = plt.hist2d(data[:, 1], data[:, 2], bins=30, normed=True)
    # xxx
    ax2 = plt.contour(y_,
                      z_,
                      np.sum(np.exp(ZZ), axis=0).T,
                      colors='w',
                      linewidths=2)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    plt.colorbar(ax2, shrink=0.8)

    fig.suptitle('EM2 PDF: ' + var_name1 + var_name2 + var_name3 + ' (t=' +
                 str(time) + ', z=' + str(z) + 'm)',
                 fontsize=20)
    plt.savefig(
        os.path.join(
            path, 'EM2_trivar_figures',
            'EM2_PDF_trivariate_' + var_name1 + var_name2 + var_name3 + '_' +
            str(time) + '_z' + str(np.int(z)) + 'm.png'))

    plt.close()

    return
Esempio n. 41
0
def make_2d_plot(dat_joined: pd.DataFrame,
                 factor_1: str,
                 factor_2: str,
                 single_sentence_plots: bool = False) -> None:
    """Create 2D quilt plot from dataframe row columns ('word_' + factor_1) and ('word_' + factor_2).

    :param dat_joined: Dataframe of the format returned by pull_mentions
    :param factor_1: x-axis of the graph, possible entries 'virus', 'therapy', 'drug', 'exp'
    :param factor_2: y-axis of the graph, possible entries 'virus', 'therapy', 'drug', 'exp'
    :param single_sentece_plots: If true, plot only coocurrences in the same sentence
    """
    if single_sentence_plots:
        grouped = dat_joined[dat_joined.same_sentence is True].groupby(
            ['word_' + factor_1, 'word_' + factor_2])
    else:
        grouped = dat_joined.groupby(['word_' + factor_1, 'word_' + factor_2])

    values = grouped.count().values[:, 0]

    index = grouped.count().index

    # Holds aggregated, in order appearences of factor_1 and factor_2 respectively
    index_1, index_2 = zip(*index)

    uniq_1 = np.unique(index_1)
    uniq_2 = np.unique(index_2)

    # Populates index_1 and index_2 with the index they appear in uniq_1 and uniq_2 respectively
    for i in range(0, len(index_1)):
        index_1[i] = np.where(index_1[i] == uniq_1)[0][0]
        index_2[i] = np.where(index_2[i] == uniq_2)[0][0]

    pylab.figure(figsize=(5, 5), dpi=200)
    hist = pylab.hist2d(index_1,
                        index_2,
                        (range(0,
                               len(uniq_1) + 1), range(0,
                                                       len(uniq_2) + 1)),
                        weights=values,
                        cmap='Blues')
    pylab.xticks(np.arange(0, len(uniq_1)) + 0.5, uniq_1, rotation=90)
    pylab.yticks(np.arange(0, len(uniq_2)) + 0.5, uniq_2)
    pylab.clim(0, np.max(hist[0]) * 1.5)
    for i in range(0, len(uniq_1)):
        for j in range(0, len(uniq_2)):
            pylab.text(i + 0.5,
                       j + 0.5,
                       int(hist[0][i][j]),
                       ha='center',
                       va='center')

    pylab.colorbar()
    if single_sentence_plots:
        pylab.title(factor_1 + " and " + factor_2 + " in One Sentence")
        pylab.tight_layout()
        pylab.savefig("Overlap" + factor_1 + "_Vs_" + factor_2 +
                      "_2D_sentence.png",
                      bbox_inches='tight',
                      dpi=200)
    else:
        pylab.title(factor_1 + " and " + factor_2 + " in One Block")
        pylab.tight_layout()
        pylab.savefig("Overlap" + factor_1 + "_Vs_" + factor_2 +
                      "_2D_block.png",
                      bbox_inches='tight',
                      dpi=200)
Esempio n. 42
0
def plot_PDF_log(data, x_, y_, z_, ZZ, var_name1, var_name2, var_name3, score, amp_qt, amp_w, z):
    fig = plt.figure(figsize=(20, 15))

    plt.subplot(3, 5, 1)
    plt.scatter(data[:, 0], data[:, 1], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.subplot(3, 5, 2)
    ax1 = plt.hist2d(data[:, 0], data[:, 1], bins=30, norm=LogNorm(), normed=True)
    plt.colorbar(shrink=0.8)
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.title('data histogram')
    plt.subplot(3, 5, 3)
    ax1 = plt.contourf(x_, y_, np.sum(np.exp(ZZ),axis=2).T, norm=LogNorm())
    plt.colorbar(ax1, shrink=0.8)
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name2, amp_qt, amp_w)
    plt.subplot(3, 5, 4)
    ax1 = plt.hist2d(data[:, 0], data[:, 1], bins=30, normed=True, norm=LogNorm())
    # xxx
    lvls = np.logspace(-1, 6, 10)
    ax2 = plt.contour(x_, y_, np.sum(np.exp(ZZ), axis=2).T, levels=lvls, colors='w', norm=LogNorm(), linewidths=3)
    plt.colorbar(ax2, shrink=0.8)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name2, amp_qt, amp_w)

    plt.subplot(3, 5, 6)
    plt.scatter(data[:, 0], data[:, 2], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 7)
    ax1 = plt.hist2d(data[:, 0], data[:, 2], bins=30, norm=LogNorm(), normed=True)
    plt.colorbar(shrink=0.8)
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.title('data histogram')
    plt.subplot(3, 5, 8)
    # xxx
    ax1 = plt.contourf(x_, z_, np.sum(np.exp(ZZ), axis=1).T, norm=LogNorm())
    # xxx
    plt.colorbar(ax1, shrink=0.8)
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 9)
    ax1 = plt.hist2d(data[:,0], data[:, 2], bins=30, normed=True, norm=LogNorm())
    # xxx
    # lvls = np.exp(np.arange(-5,6,1))
    lvls = np.logspace(-1, 5, 10)
    ax2 = plt.contour(x_, z_ , np.sum(np.exp(ZZ), axis=1).T, levels=lvls, colors='w', norm=LogNorm(), linewidths=3)
    plt.colorbar(ax2,shrink=0.8)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name1, var_name3, amp_qt, amp_w)

    plt.subplot(3, 5, 11)
    plt.scatter(data[:, 1], data[:, 2], s=2, alpha=0.3)
    plt.title('data')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    plt.subplot(3, 5, 12)
    ax1 = plt.hist2d(data[:, 1], data[:, 2], bins=30, norm=LogNorm(), normed=True)
    plt.colorbar(shrink=0.8)
    plt.title('data histogram')
    plt.subplot(3, 5, 13)
    # xxx
    ax1 = plt.contourf(y_, z_, np.sum(np.exp(ZZ), axis=0).T, norm=LogNorm())
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    plt.colorbar(ax1, shrink=0.8)
    plt.subplot(3, 5, 14)
    ax1 = plt.hist2d(data[:,1], data[:,2], bins=30, normed=True, norm=LogNorm())
    # xxx
    lvls = np.logspace(-1, 6, 10)
    ax2 = plt.contour(y_, z_, np.sum(np.exp(ZZ), axis=0).T, levels=lvls, colors='w', linewidths=3, norm=LogNorm())
    plt.colorbar(ax2, shrink=0.8)
    # xxx
    plt.title('EM2 PDF')
    axis_label(var_name2, var_name3, amp_qt, amp_w)
    # plt.colorbar(ax1, shrink=0.8)


    fig.suptitle('EM2 PDF: ' + var_name1 + var_name2 + var_name3 + ' (score=' + str(score) + '; z=' + str(z) + 'm)',
                 fontsize=20)
    plt.savefig(os.path.join(
        fullpath_out,'EM2_trivar_alltimes_figures','EM2_PDF_trivariate_' + var_name1 + var_name2 + var_name3 + '_z' + str(
            np.int(z)) + 'm_log.png')
    )

    plt.close()

    return
    print round(np.mean(ecart_abs),3)
    fig1 = plt.figure()
    fig1.suptitle('histogramme (scores mesures - predictions)', fontsize=14, fontweight='bold')
    plt.xlabel('valeur des ecarts')
    plt.ylabel("# d'ecarts")

    bins = np.arange(-1.0,1.0,0.05)
    plt.hist(ecart, bins, normed=True)
    fig1.savefig('spkshow_histo_ecart')
    plt.show()

    fig1 = plt.figure()
    fig1.suptitle('predictions / scores mesures', fontsize=14, fontweight='bold')
    plt.ylabel('prediction')
    plt.xlabel("scores mesures")

    bins = np.arange(0,1.01,0.05)
    plt.plot(x, y, 'ro') 
    plt.axis([0,1,0,1])
    plt.grid()
    fig1.savefig('spkshow_nuage')
    plt.show() 

    fig1 = plt.figure()
    fig1.suptitle('predictions / scores mesures', fontsize=14, fontweight='bold')
    plt.ylabel('prediction')
    plt.xlabel("scores mesures")
    plt.hist2d(x,y,bins=50);
    fig1.savefig('spkshow_nuage2D')
    plt.show()
Esempio n. 44
0
            pl.yticks([])
            

            
            
            
            
            
        # Plot the 2D histograms
            
        pl.figure()
        prediction = predicted_distances[square_slice].flatten()
        results = out.flatten()
        labels = true_distances[square_slice].flatten()
        n_binsX = np.max(labels)-np.min(labels)
        n_binsY = np.max(prediction)-np.min(prediction)
        pl.subplot(1,2,1)
        pl.hist2d(labels, prediction, (n_binsX, n_binsY), cmap=pl.cm.jet, norm=pl.mpl.colors.LogNorm())
        pl.xlabel('ground truth')
        pl.ylabel('noisy distance map')
        pl.title('2d histogram of noisy distance')
        
        n_binsY = np.max(results)-np.min(results)
        
        pl.subplot(1,2,2)
        pl.hist2d(labels, results, (n_binsX, n_binsY), cmap=pl.cm.jet, norm=pl.mpl.colors.LogNorm())
        pl.xlabel('ground truth')
        pl.ylabel('smoothed distance map')
        pl.title('2d histogram of smoothed distance')
        pl.show()
Esempio n. 45
0
def corner(samples,labels):
    N=len(labels)
    from matplotlib.colors import LogNorm
    
    py.figure(figsize=(12,12))
    
    axes={}
    for i,l1 in enumerate(labels):
        for j,l2 in enumerate(labels):
            if j>i:
                continue
                
            ax = py.subplot2grid((N,N),(i, j))
            axes[(i,j)]=ax
            
            idx_y=labels.index(l1)
            idx_x=labels.index(l2)
            x,y=samples[:,idx_x],samples[:,idx_y]
            
            if i==j:
                # plot distributions
                xx,yy=histogram(x,bins=200,plot=False)
                py.plot(xx,yy,'-o',markersize=3)
                py.gca().set_yticklabels([])
                
                if i==(N-1):
                    py.xlabel(l2)
                    [l.set_rotation(45) for l in ax.get_xticklabels()]
                else:
                    ax.set_xticklabels([])
                
            else:
                counts,ybins,xbins,image = py.hist2d(x,y,bins=100,norm=LogNorm())
                #py.contour(counts,extent=[xbins.min(),xbins.max(),ybins.min(),ybins.max()],linewidths=3)
                
                if i==(N-1):
                    py.xlabel(l2)
                    [l.set_rotation(45) for l in ax.get_xticklabels()]
                else:
                    ax.set_xticklabels([])
                    
                if j==0:
                    py.ylabel(l1)
                    [l.set_rotation(45) for l in ax.get_yticklabels()]
                else:
                    ax.set_yticklabels([])
    
    # make all the x- and y-lims the same
    j=0
    lims=[0]*N
    for i in range(1,N):
        ax=axes[(i,0)]
        lims[i]=ax.get_ylim()

        if i==N-1:
            lims[0]=ax.get_xlim()
    
        
    for i,l1 in enumerate(labels):
        for j,l2 in enumerate(labels):
            if j>i:
                continue
                
            ax=axes[(i,j)]
            
            if j==i:
                ax.set_xlim(lims[i])
            else:
                ax.set_ylim(lims[i])
                ax.set_xlim(lims[j])
Esempio n. 46
0
def plot_PDF_samples_log(data, var_name1, var_name2, clf, amp, time, z):
    import matplotlib.mlab as mlab
    import matplotlib.cm as cm

    det1 = np.linalg.det(clf.covariances_[0, :, :])
    det2 = np.linalg.det(clf.covariances_[1, :, :])
    det_ = min(det1, det2)
    fact_ = 1. / np.sqrt((2 * np.pi)**2 * det_)
    fact = 1.1 * clf.weights_[0] * 1. / np.sqrt(
        (2 * np.pi)**2 * det1) + clf.weights_[1] * 1. / np.sqrt(
            (2 * np.pi)**2 * det2)

    # Plotting
    n_sample = 300
    x1_max = np.amax(data[:, 0])
    x1_min = np.amin(data[:, 0])
    x2_max = np.amax(data[:, 1])
    x2_min = np.amin(data[:, 1])
    x = np.linspace(x1_min, x1_max, n_sample)
    y = np.linspace(x2_min, x2_max, n_sample)
    X, Y = np.meshgrid(x, y)
    XX = np.array([X.ravel(), Y.ravel()]).T
    Z = clf.score_samples(XX).reshape(X.shape)
    mx1 = clf.means_[0, 0]
    my1 = clf.means_[0, 1]
    sx1 = np.sqrt(clf.covariances_[0, 0, 0])
    sy1 = np.sqrt(clf.covariances_[0, 1, 1])
    sxy1 = clf.covariances_[0, 1, 0]
    mx2 = clf.means_[1, 0]
    my2 = clf.means_[1, 1]
    sx2 = np.sqrt(clf.covariances_[1, 0, 0])
    sy2 = np.sqrt(clf.covariances_[1, 1, 1])
    sxy2 = clf.covariances_[1, 1, 0]
    Z1 = mlab.bivariate_normal(X,
                               Y,
                               sigmax=sx1,
                               sigmay=sy1,
                               mux=mx1,
                               muy=my1,
                               sigmaxy=sxy1)
    Z2 = mlab.bivariate_normal(X,
                               Y,
                               sigmax=sx2,
                               sigmay=sy2,
                               mux=mx2,
                               muy=my2,
                               sigmaxy=sxy2)

    fig = plt.figure(figsize=(10, 12))
    levels_tot = np.linspace(0, fact, 10)
    if fact <= 2:
        levels_cont = np.arange(0, fact, 0.2)
        levels_contf = np.arange(0, fact, 0.2)
    elif fact <= 10:
        levels_cont = np.arange(0, fact, 0.5)
        levels_contf = np.arange(0, fact, 0.5)
    elif fact <= 20:
        levels_cont = np.arange(0, fact, 2)
        levels_contf = np.arange(0, fact, 2)
    elif fact <= 50:
        levels_cont = np.arange(0, fact, 5)
        levels_contf = np.arange(0, fact, 5)
    else:
        levels_cont = np.arange(0, fact, 20)
        levels_contf = np.arange(0, fact, 20)
    levels_comp = np.linspace(0, fact_, 7)

    plt.subplot(3, 2, 1)
    plt.scatter(data[:, 0], data[:, 1], s=2, alpha=0.3)
    ax1 = plt.contour(X, Y, Z, levels=np.linspace(10, 20, 2))
    plt.colorbar(ax1, shrink=0.8)
    plt.xlim([x1_min, x1_max])
    plt.ylim([x2_min, x2_max])
    plt.title(var_name1 + var_name2 + ' (data), t=' + str(time) + ', z=' +
              str(z))
    plt.xlim([x1_min, x1_max])
    plt.ylim([x2_min, x2_max])
    plt.title(var_name1 + var_name2 + ' (data)')
    axis_label(var_name1, var_name2, amp)

    plt.subplot(3, 2, 3)
    ax1 = plt.hist2d(data[:, 0],
                     data[:, 1],
                     bins=30,
                     normed=True,
                     norm=colors.LogNorm())
    plt.colorbar(shrink=0.8)
    ax2 = plt.contour(X,
                      Y,
                      np.exp(Z),
                      norm=colors.LogNorm(),
                      linewidths=2,
                      colors='w')
    axis_label(var_name1, var_name2, amp)
    plt.title('data histogram')
    plt.subplot(3, 2, 4)
    ax1 = plt.contourf(X, Y, np.exp(Z), norm=colors.LogNorm())
    plt.colorbar(ax1, shrink=0.8)
    plt.title('EM PDF')
    axis_label(var_name1, var_name2, amp)
    plt.subplot(3, 2, 5)
    plt.scatter(data[:, 0], data[:, 1], s=2, alpha=0.05)
    ax1 = plt.contour(X, Y, Z1, norm=colors.LogNorm(), linewidths=1.5)
    ax2 = plt.contour(X, Y, Z2, norm=colors.LogNorm(), linewidths=1.5)
    plt.plot([clf.means_[0, 0]], [clf.means_[0, 1]], 'wo', markersize=6)
    plt.plot([clf.means_[1, 0]], [clf.means_[1, 1]], 'wo', markersize=6)
    plt.colorbar(ax1, shrink=0.8)
    plt.title('f1, f2')
    plt.xlim([x1_min, x1_max])
    plt.ylim([x2_min, x2_max])
    axis_label(var_name1, var_name2, amp)
    plt.subplot(3, 2, 6)
    plt.scatter(data[:, 0], data[:, 1], s=2, alpha=0.05)
    ax1 = plt.contour(X, Y, np.exp(Z), norm=colors.LogNorm(), linewidths=1.5)
    plt.plot([clf.means_[0, 0]], [clf.means_[0, 1]], 'wo', markersize=6)
    plt.plot([clf.means_[1, 0]], [clf.means_[1, 1]], 'wo', markersize=6)
    plt.colorbar(ax1, shrink=0.8)
    plt.xlim([x1_min, x1_max])
    plt.ylim([x2_min, x2_max])
    axis_label(var_name1, var_name2, amp)
    plt.title('f = f1 + f2')

    fig.suptitle('EM2 PDF: ' + var_name1 + var_name2 + ' (t=' + str(time) +
                 ', z=' + str(z) + 'm)',
                 fontsize=20)
    plt.savefig(
        os.path.join(
            fullpath_out, 'EM2_bivar_figures',
            'EM2_PDF_bivariate_' + var_name1 + '_' + var_name2 + '_' +
            str(time) + '_z' + str(np.int(z)) + 'm_log.png'))

    plt.close()
    return
def singlehist2d(x,y, quad):
    counts, xedges, yedges, Image = pylab.hist2d(x,y,bins=20)
    quad.set_array(counts)
    return quad
Esempio n. 48
0
    plt.savefig(os.path.join(folder_output, 'Feature_Importances.jpg'))
    plt.close()

    # show the validation of the test set
    plt.figure()
    # label of the axis.
    plt.xlabel(
        'In-situ soil moisture [$\mathregular{cm^3}$/$\mathregular{cm^3}$]',
        fontsize=12)
    plt.ylabel(
        'Estimated soil moisture [$\mathregular{cm^3}$/$\mathregular{cm^3}$]',
        fontsize=12)
    # plot the data with the density (number of pixels)
    h = hist2d(list(test_labels),
               list(predictions),
               bins=40,
               cmap='PuBu',
               range=[[0, 0.6], [0, 0.6]])
    cb = plt.colorbar()
    cb.set_label('Numbers of points')
    # Add 1:1 line
    x = np.arange(0, 0.6, 0.1, dtype=float)
    y = x
    # Add the information of RMSE and r on the figure.
    plt.text(0.1, 0.54, 'RMSE: %.2f' % rmse, fontdict={'size': 12})
    plt.text(0.1,
             0.50,
             'ubRMSE: %.2f' % cal_ubrmse(test_labels, predictions)[0],
             fontdict={'size': 12})
    plt.text(0.1, 0.46, 'r: %.2f' % r, fontdict={'size': 12})
    plt.text(0.1, 0.42, 'Num: %d' % len(test_features), fontdict={'size': 12})
"""
Example script for plotting histogram 
"""

# import every function from numpy module
# can use the function directly from now
from numpy import *
# import pylab module
# use pylab.function to call 
import pylab

# generating data
# number of data points in each dimension
N = 20000

# random number from "normal" distribution
# default: sigma = 1.0, mean = 0.0
x = random.randn(N)
y = random.randn(N)

# short cut to plot a histogram
pylab.hist2d(x,y,bins=50,cmin=0.0001)

# show() is required if using in non-interactive environment
pylab.show()
Esempio n. 50
0
matplotlib.use('pdf')
import matplotlib.pyplot as plt
import glob
import sys,numpy,pylab
file_list = glob.glob(sys.argv[1])
mt_list = [] 
tt_list = [] 
for lfile in file_list:
  try:
    llh_file = pickle.load(open(lfile, "rb"))
    mt_list.append(float("%.3f" % llh_file['result']['mt']))
    tt_list.append(float("%.5f" % llh_file['result']['tt']))
  except:
    print lfile
my_bins =101 
counts,ybins,xbins,image = pylab.hist2d(mt_list,tt_list,range=[[-0.015,0.015],[-0.1,0.1]],weights=numpy.array([float(1)/float(350) for j in mt_list]),bins=my_bins)
print xbins,ybins,counts.shape
#counts,ybins,xbins,image = pylab.hist2d(mt_list,tt_list,bins=10)
pylab.colorbar()
#pylab.xlim(-0.015,0.015)
#pylab.ylim(-0.1,0.1)
new_counts = numpy.array([[float(-1) for i in xrange(my_bins)] for j in xrange(my_bins)])
for i in xrange(((my_bins-1)/2)+1):
  if(i>0):
    p = ((my_bins-1)/2)-i
    q = ((my_bins-1)/2)+(i+1)
    tot_counts = 0
#Calculate total counts so far
    for j in xrange(p,q): 
      for k in xrange(p,q): 
        tot_counts +=counts[j][k]
from numpy import *
import pylab
import matplotlib.animation as animation

def singlehist2d(x,y, quad):
    counts, xedges, yedges, Image = pylab.hist2d(x,y,bins=20)
    quad.set_array(counts)
    return quad

fig = pylab.figure()
ax  = pylab.subplot(111)

ims = []
for ind in linspace(0.0,4.0,10):
    N = int(100*ind)
    x = random.randn(N)
    y = random.randn(N)
    
    ax.set_title('N = %i'%N)
     = pylab.hist2d(x,y,hold=False)
    ims.append((pylab.pcolor(xedges, yedges, counts),))
    
im_ani = animation.ArtistAnimation(fig, ims, interval=100, repeat_delay=3000,
    blit=True)

pylab.show()


Esempio n. 52
0
                #~ out = sr.solve_via_ILP(predicted_distances[cube], max_gradient=[1,1,2])
                t1 = time()
                
                
                
            elif isinstance(params,int):
                t0 = time()
                out = sr.reconstruct_surface(predicted_distances[cube], tmp_file1,tmp_file2,prog,overwrite=True, max_dist=max_dist, sampling = [1,1,2], clipping_dist=params, cost_fun=cost_function[:-2], verbose=True)
                t1 = time()
            elif isinstance(params,str):
                
                f = h5py.File(os.path.join(ROOT_DATA,params), 'r')
                predicted_distances_prior =  f['inference_results'].value
                true_distances_prior = f['labels'].value
                f.close()
                
                predicted_distances_prior = np.minimum(predicted_distances_prior,np.max(true_distances))
                prior = pl.hist2d(predicted_distances_prior.flatten(), true_distances_prior.flatten(), range=[[-0.5,max_dist+0.5],[-0.5,max_dist+0.5]],bins=np.linspace(-0.5,max_dist + 0.5,max_dist+2))
                prior = np.exp(-(prior[0] / prior[0].sum(axis=1)[:,np.newaxis].astype(np.float) ))*1000
                pl.close()
                t0 = time()
                out = sr.reconstruct_surface(predicted_distances[cube], tmp_file1,tmp_file2,prog,overwrite=True, max_dist=max_dist, sampling = [1,1,2], clipping_dist=params, cost_fun=prior, verbose=True)
                t1 = time()
                        
            imsave(output,out.astype(np.int32),compress=1)
            os.remove(output_flag)
            os.remove(tmp_file1)
            os.remove(tmp_file2)
            times[cost_function].append(t1-t0)
     
Esempio n. 53
0
#z reki
#pliki=["ot001", "ot002", "ot009", "ot019", "ot020" , "nt001"]; 



PtBins=[0., 0.1,1.5, 2., 2.5, 3., 3.5, 4., 4.5, 5., 6., 7., 8.,10., 12., 14., 16., 18., 20., 25., 30., 35., 40., 45.,50., 60., 70., 80., 90., 100., 120., 140.,160.];

PtWidth=[(PtBins[j+1]-PtBins[j]) for j in range(len(PtBins)-1)]

bin_width = 0.01;
rec = root2rec(sys.argv[1], "tvec")
       
#x = np.extract(np.absolute(rec.Teta) < 1.61, rec.Tbeta)
x = np.extract(np.logical_and(np.logical_and(np.absolute(rec.Teta0) < 1.61, rec.Tlbx_1), rec.Tpt0 > 10), rec.Teta0);
y = np.extract(np.logical_and(np.logical_and(np.absolute(rec.Teta0) < 1.61, rec.Tlbx_1), rec.Tpt0 > 10), rec.Tphi0);


print  len(x), len(y)

pl.hist2d(x, y, bins=200, norm=LogNorm())
#pl.hist2d(x, y, bins=np.arange(0.,4,bin_width) , norm=LogNorm())
pl.colorbar()
#plt.xscale('log')
plt.ylabel(r'$\phi$')
plt.xlabel(r'$\eta$')
plt.draw()
pp.savefig()
pp.close()
plt.show()
Esempio n. 54
0
#      if(math.fabs(mt)>0.001):
        print dm2,th23,dm21,th231,2*(float("%.5f" % llh_file1['result']['llh'])-float("%.5f" % llh_file['result']['llh']))
        llh_diff.append(2*(float("%.5f" % llh_file1['result']['llh'])-float("%.5f" % llh_file['result']['llh'])))
    n_pull.append((float("%.5f" % llh_file['result']['norm'])-1)/0.5)
    ne_pull.append((float("%.5f" % llh_file['result']['norm_e'])-1)/1)
    g_pull.append((float("%.5f" % llh_file['result']['gamma'])-0)/5)
    atm_pull.append((float("%.5f" % llh_file['result']['atmmu_fraction'])-0.01)/1)
    de_pull.append((float("%.5f" % llh_file['result']['domeff'])-1)/0.3)
    hi_pull.append((float("%.5f" % llh_file['result']['hole_ice'])-0.02)/0.02)
  except:
    pass
    #print lfile
print len(llh_diff),len(n_pull)
from scipy import stats
print 'lists',count,count1,len(mt_list),len(mtp_list)
pylab.hist2d(mt_list+mtp_list,exp_rat,bins=20)
pylab.xlabel(r"Fitted $\theta_{23}$")
#pylab.xlabel(r"Fitted $sin^2(2 \theta_{23})$")
pylab.ylabel("Events/5174")
pylab.colorbar()
pylab.savefig("ElimPlot.pdf")
pylab.close()
pylab.hist2d(ttdiff_list+ttpdiff_list,exp1_rat,bins=20)
pylab.xlabel(r"Fitted $\theta_{23}$")
#pylab.xlabel(r"Fitted $sin^2(2 \theta_{23})$")
pylab.ylabel("Events/5174")
pylab.colorbar()
pylab.savefig("ElimPlot1.pdf")
pylab.close()
#pylab.hist(mt_list+mtp_list,bins=numpy.linspace(-0.01,0.01,30),color='k',histtype='step')
#pylab.hist(mt_list+mtp_list,bins=numpy.linspace(0.7,1.2,40),color='k',histtype='step')
Esempio n. 55
0
    numpy
    matplotlib
'''

import argparse
from matplotlib.colors import LogNorm
import numpy as np
import pylab
import sys

if __name__ == '__main__':
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-i', '--input',
            type = argparse.FileType('r', encoding = 'utf8'),
            default = sys.stdin,
            help = 'input file')
    parser.add_argument('--num-bins',
            type = int, default = 50,
            help = 'number of bins in x and y direction')
    parser.add_argument('-d',
            type = str, default = ' ',
            help = 'delimiter')

    args = parser.parse_args()

    x, y = np.loadtxt(args.input, delimiter = args.delimiter, unpack = True)

    pylab.hist2d(x,y,bins=args.num_bins,norm=LogNorm())
    pylab.colorbar()
    pylab.show()
Esempio n. 56
0
def plot_PDF_samples(data, var_name1, var_name2, clf, time, z):
    import matplotlib.mlab as mlab
    import matplotlib.cm as cm

    det_ = np.linalg.det(clf.covariances_[0, :, :])
    fact_ = 1. / np.sqrt((2 * np.pi)**2 * det_)

    # Plotting
    n_sample = 300
    x1_max = np.amax(data[:, 0])
    x1_min = np.amin(data[:, 0])
    x2_max = np.amax(data[:, 1])
    x2_min = np.amin(data[:, 1])
    x = np.linspace(x1_min, x1_max, n_sample)
    y = np.linspace(x2_min, x2_max, n_sample)
    X, Y = np.meshgrid(x, y)
    XX = np.array([X.ravel(), Y.ravel()]).T
    Z = clf.score_samples(XX).reshape(X.shape)
    mx1 = clf.means_[0, 0]
    my1 = clf.means_[0, 1]
    sx1 = np.sqrt(clf.covariances_[0, 0, 0])
    sy1 = np.sqrt(clf.covariances_[0, 1, 1])
    sxy1 = clf.covariances_[0, 1, 0]
    Z1 = mlab.bivariate_normal(X,
                               Y,
                               sigmax=sx1,
                               sigmay=sy1,
                               mux=mx1,
                               muy=my1,
                               sigmaxy=sxy1)

    plt.figure(figsize=(12, 12))
    levels_tot = np.linspace(0, fact_, 10)
    if fact_ <= 2:
        levels_cont = np.arange(0, fact_, 0.2)
        levels_contf = np.arange(0, fact_, 0.2)
    elif fact_ <= 10:
        levels_cont = np.arange(0, fact_, 0.5)
        levels_contf = np.arange(0, fact_, 0.5)
    elif fact_ <= 20:
        levels_cont = np.arange(0, fact_, 2)
        levels_contf = np.arange(0, fact_, 2)
    elif fact_ <= 50:
        levels_cont = np.arange(0, fact_, 5)
        levels_contf = np.arange(0, fact_, 5)
    else:
        levels_cont = np.arange(0, fact_, 20)
        levels_contf = np.arange(0, fact_, 20)
    levels_comp = np.linspace(0, fact_, 7)

    plt.subplot(3, 2, 1)
    plt.scatter(data[:, 0], data[:, 1], s=2, alpha=0.05)
    ax1 = plt.contour(X, Y, Z, levels=np.linspace(10, 20, 2))
    plt.colorbar(ax1, shrink=0.8)
    plt.xlim([x1_min, x1_max])
    plt.ylim([x2_min, x2_max])
    plt.title(var_name1 + var_name2 + ' (data), t=' + str(time) + ', z=' +
              str(z))
    plt.xlabel(var_name1)
    plt.ylabel(var_name2)
    plt.colorbar(ax1, shrink=0.8)
    plt.xlim([x1_min, x1_max])
    plt.ylim([x2_min, x2_max])
    plt.title(var_name1 + var_name2 + ' (data), t=' + str(time) + ', z=' +
              str(z))
    plt.xlabel(var_name1)
    plt.ylabel(var_name2)

    plt.subplot(3, 2, 3)
    ax1 = plt.hist2d(data[:, 0], data[:, 1], bins=30, normed=True)
    plt.colorbar(shrink=0.8)
    ax2 = plt.contour(X,
                      Y,
                      np.exp(Z),
                      levels=levels_cont,
                      linewidths=1,
                      colors='w')
    plt.xlabel(var_name1)
    plt.ylabel(var_name2)
    plt.title('data histogram')
    plt.subplot(3, 2, 4)
    ax1 = plt.contourf(X, Y, np.exp(Z), levels=levels_contf)
    plt.colorbar(ax1, shrink=0.8)
    plt.title('EM PDF')
    plt.xlabel(var_name1)
    plt.ylabel(var_name2)
    plt.subplot(3, 2, 5)
    plt.scatter(data[:, 0], data[:, 1], s=2, alpha=0.05)
    ax1 = plt.contour(X, Y, Z1, levels=levels_comp, linewidths=1.5)
    plt.plot([clf.means_[0, 0]], [clf.means_[0, 1]], 'wo', markersize=6)
    plt.colorbar(ax1, shrink=0.8)
    plt.title('f1, f2')
    plt.xlim([x1_min, x1_max])
    plt.ylim([x2_min, x2_max])
    plt.xlabel(var_name1)
    plt.ylabel(var_name2)
    plt.subplot(3, 2, 6)
    plt.scatter(data[:, 0], data[:, 1], s=2, alpha=0.05)
    ax1 = plt.contour(X, Y, np.exp(Z), levels=levels_cont, linewidths=1.5)
    # ax1 = plt.contour(X, Y, Z1+Z2, linewidths=1.5)
    plt.plot([clf.means_[0, 0]], [clf.means_[0, 1]], 'wo', markersize=6)
    plt.colorbar(ax1, shrink=0.8)
    plt.xlim([x1_min, x1_max])
    plt.ylim([x2_min, x2_max])
    plt.xlabel(var_name1)
    plt.ylabel(var_name2)
    plt.title('f = f1 + f2')

    plt.savefig(fullpath_out + 'CloudClosure_alltimes_figures/CC_bivariate_' +
                var_name1 + '_' + var_name2 + '_z' + str(np.int(z)) +
                'm_alltime.png')

    plt.close()
    return
Esempio n. 57
0
    def plot(self, bins=100, cmap="hot_r", fontsize=10, Nlevels=4,
        xlabel=None, ylabel=None, norm=None, range=None,
        contour=True, **kargs):
        """plots histogram of mean across replicates versus coefficient variation

        :param int bins: binning for the 2D histogram
        :param fontsize: fontsize for the labels
        :param contour: show some contours
        :param int Nlevels: must be more than 2
        :param range: as in pylab.hist2d : a 2x2 shape [[-3,3],[-4,4]]

        .. plot::
            :include-source:
            :width: 50%

            >>> from msdas import *
            >>> r = replicates.ReplicatesYeast(get_yeast_raw_data())
            >>> r.drop_na_count(54) # to speed up the plot creation
            >>> r.hist2d_mu_versus_cv()

        """

        X = self.df[self.df.columns[0]].values
        Y = self.df[self.df.columns[1]].values
        if len(X) > 10000:
            print("Computing 2D histogram. Please wait")

        pylab.clf()
        if norm == 'log':
            from matplotlib import colors
            res = pylab.hist2d(X, Y, bins=bins,
               cmap=cmap, norm=colors.LogNorm())
        else:
            res = pylab.hist2d(X, Y, bins=bins, cmap=cmap, range=range)

        pylab.colorbar()

        if contour:
            try:
                bins1 = bins[0]
                bins2 = bins[1]
            except:
                bins1 = bins
                bins2 = bins

            X, Y = pylab.meshgrid(res[1][0:bins1], res[2][0:bins2])
            if contour:
                levels = [round(x) for x in pylab.logspace(0, pylab.log10(res[0].max().max()),Nlevels)]
                pylab.contour(X, Y, res[0].transpose(), levels[2:], color="g")
                #pylab.clabel(C, fontsize=fontsize, inline=1)

        if ylabel == None:
            ylabel = self.df.columns[1]
        if xlabel == None:
            xlabel = self.df.columns[0]

        pylab.xlabel(xlabel, fontsize=fontsize)
        pylab.ylabel(ylabel, fontsize=fontsize)

        pylab.grid(True)
        return res
Esempio n. 58
0
    def plot(self,
             bins=100,
             cmap="hot_r",
             fontsize=10,
             Nlevels=4,
             xlabel=None,
             ylabel=None,
             norm=None,
             range=None,
             normed=False,
             colorbar=True,
             contour=True,
             grid=True,
             **kargs):
        """plots histogram of mean across replicates versus coefficient variation

        :param int bins: binning for the 2D histogram (either a float or list
            of 2 binning values).
        :param cmap: a valid colormap (defaults to hot_r)
        :param fontsize: fontsize for the labels
        :param int Nlevels: must be more than 2
        :param str xlabel: set the xlabel (overwrites content of the dataframe)
        :param str ylabel: set the ylabel (overwrites content of the dataframe)
        :param norm: set to 'log' to show the log10 of the values.
        :param normed: normalise the data
        :param range: as in pylab.Hist2D : a 2x2 shape [[-3,3],[-4,4]]
        :param contour: show some contours (default to True)
        :param bool grid: Show unerlying grid (defaults to True)

        If the input is a dataframe, the xlabel and ylabel will be populated
        with the column names of the dataframe.

        """
        X = self.df[self.df.columns[0]].values
        Y = self.df[self.df.columns[1]].values
        if len(X) > 10000:
            print("Computing 2D histogram. Please wait")

        pylab.clf()
        if norm == 'log':
            from matplotlib import colors
            res = pylab.hist2d(X,
                               Y,
                               bins=bins,
                               density=normed,
                               cmap=cmap,
                               norm=colors.LogNorm())
        else:
            res = pylab.hist2d(X,
                               Y,
                               bins=bins,
                               cmap=cmap,
                               density=normed,
                               range=range)

        if colorbar is True:
            pylab.colorbar()

        if contour:
            try:
                bins1 = bins[0]
                bins2 = bins[1]
            except:
                bins1 = bins
                bins2 = bins

            X, Y = pylab.meshgrid(res[1][0:bins1], res[2][0:bins2])
            if contour:
                if res[0].max().max() < 10 and norm == 'log':
                    pylab.contour(X, Y, res[0].transpose())
                else:
                    levels = [
                        round(x) for x in pylab.logspace(
                            0, pylab.log10(res[0].max().max()), Nlevels)
                    ]
                    pylab.contour(X, Y, res[0].transpose(), levels[2:])
                #pylab.clabel(C, fontsize=fontsize, inline=1)

        if ylabel is None:
            ylabel = self.df.columns[1]
        if xlabel is None:
            xlabel = self.df.columns[0]

        pylab.xlabel(xlabel, fontsize=fontsize)
        pylab.ylabel(ylabel, fontsize=fontsize)

        if grid is True:
            pylab.grid(True)

        return res
Esempio n. 59
0
    se = good[np.in1d(good[OBJECT_ID],coadd[OBJECT_ID])]

    uid,inv,cts = np.unique(se[OBJECT_ID],False,True,True)
    
    if not (uid == coadd[OBJECT_ID]).all():
        raise Exception("Object IDs do not match")

    kwargs = dict(bins=100,histtype='step',lw=1.5)

    # Spatial distribution
    maglim = 30

    plt.figure()
    sel = (se['MAG_PSF'] < maglim) & (se['BAND'] == 'g')
    plt.hist2d(se['RA'][sel],se['DEC'][sel],bins=250,norm=colors.LogNorm())
    plt.colorbar(label='log(Counts)')
    plt.title('HPX %05d (g < 30)'%opts.pix)
    plt.xlabel('RA (deg)')
    plt.ylabel('DEC (deg)')
    plt.savefig(pltdir+'spatial_se_%05d.png'%opts.pix)
     
    plt.figure()
    sel = coadd['MAG_PSF_G'] < maglim
    plt.hist2d(coadd['RA'][sel],coadd['DEC'][sel],bins=250,norm=colors.LogNorm())
    plt.colorbar(label='log(Counts)')
    plt.title('HPX %05d (g < %s)'%(opts.pix,maglim))
    plt.xlabel('RA (deg)')
    plt.ylabel('DEC (deg)')
    plt.savefig(pltdir+'spatial_coadd_%05d.png'%opts.pix)