Python matplotlib.pyplot 模块,scatter() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用matplotlib.pyplot.scatter()

项目:Python-Machine-Learning-Cookbook    作者:PacktPublishing    | 项目源码 | 文件源码
def perform_clustering(X, connectivity, title, num_clusters=3, linkage='ward'):
    plt.figure()
    model = AgglomerativeClustering(linkage=linkage, 
                    connectivity=connectivity, n_clusters=num_clusters)
    model.fit(X)

    # extract labels
    labels = model.labels_

    # specify marker shapes for different clusters
    markers = '.vx'

    for i, marker in zip(range(num_clusters), markers):
        # plot the points belong to the current cluster
        plt.scatter(X[labels==i, 0], X[labels==i, 1], s=50, 
                    marker=marker, color='k', facecolors='none')

    plt.title(title)
项目:hippylib    作者:hippylib    | 项目源码 | 文件源码
def plot_pts(points, values, colorbar=True, subplot_loc=None, mytitle=None, show_axis='on', vmin=None, vmax=None, xlim=(0,1), ylim=(0,1)):
    if subplot_loc is not None:
        plt.subplot(subplot_loc)

    pp = plt.scatter(points[:,0], points[:,1], c=values.get_local(), marker=",", s=20, vmin=vmin, vmax=vmax)

    plt.axis(show_axis)

    if colorbar:
        plt.colorbar(pp, fraction=.1, pad=0.2)
    else:
        plt.gca().set_aspect('equal')

    if mytitle is not None:
        plt.title(mytitle, fontsize=20)

    if xlim is not None:
        plt.xlim(xlim)

    if ylim is not None:
        plt.ylim(ylim)

    return pp
项目:genomedisco    作者:kundajelab    | 项目源码 | 文件源码
def main():
    parser = generate_parser()
    args = parser.parse_args()
    infile1 = h5py.File(args.input1, 'r')
    infile2 = h5py.File(args.input2, 'r')
    resolutions = numpy.intersect1d(infile1['resolutions'][...], infile2['resolutions'][...])
    chroms = numpy.intersect1d(infile2['chromosomes'][...], infile2['chromosomes'][...])
    results = {}
    data1 = load_data(infile1, chroms, resolutions)
    data2 = load_data(infile2, chroms, resolutions)
    infile1.close()
    infile2.close()
    results = {}
    results[(args.input1.split('/')[-1].strip('.quasar'), args.input2.split('/')[-1].strip('.quasar'))] = correlate_samples(data1, data2)
    for resolution in data1.keys():
        for chromo in chroms:
            plt.scatter(data1[resolution][chromo][1].flatten(),data2[resolution][chromo][1].flatten(),alpha=0.1,color='red')
            plt.show()
            plt.savefig(args.output+'.res'+str(resolution)+'.chr'+chromo+'.pdf')
项目:CausalGAN    作者:mkocaoglu    | 项目源码 | 文件源码
def scatter2d(x,y,title='2dscatterplot',xlabel=None,ylabel=None):
    fig=plt.figure()
    plt.scatter(x,y)
    plt.title(title)
    if xlabel:
        plt.xlabel(xlabel)
    if ylabel:
        plt.ylabel(ylabel)

    if not 0<=np.min(x)<=np.max(x)<=1:
        raise ValueError('summary_scatter2d title:',title,' input x exceeded [0,1] range.\
                         min:',np.min(x),' max:',np.max(x))
    if not 0<=np.min(y)<=np.max(y)<=1:
        raise ValueError('summary_scatter2d title:',title,' input y exceeded [0,1] range.\
                         min:',np.min(y),' max:',np.max(y))

    plt.xlim([0,1])
    plt.ylim([0,1])
    return fig
项目:code-uai16    作者:thanhan    | 项目源码 | 文件源码
def plot_gold(g1, g2, lc, p = 0):
    """
    plot sen/spe of g1 against g2
    only consider workers in lc
    """

    mv = crowd_model.mv_model(lc)
    s1 = []; s2 = []

    for w in g1.keys():
        if w in g2 and g1[w][p] != None and g2[w][p] != None and w in mv.dic_ss:
            s1.append(g1[w][p])
            s2.append(g2[w][p])

    plt.xticks((0, 0.5, 1), ("0", "0.5", "1"))
    plt.tick_params(labelsize = 25)
    plt.yticks((0, 0.5, 1), ("0", "0.5", "1"))

    plt.xlim(0,1)
    plt.ylim(0,1)
    plt.scatter(s1, s2, marker = '.', s=50, c = 'black')

    plt.xlabel('task 1 sen.', fontsize = 25)
    plt.ylabel('task 2 sen.', fontsize = 25)
项目:code-uai16    作者:thanhan    | 项目源码 | 文件源码
def plot_multi_err():
    """
    """
    f = open('gzoo1000000_1_2_0.2_pickle.pkl')
    res = pickle.load(f)
    sing = res[(0.5, 'single')]
    multi = res[(0.5, 'multi')]
    (g1, g2, g3, g4) = load_gold()

    a = []; b = []
    for w in multi:
        a.append(abs(g2[w][0]- sing[w][0])); b.append(abs(g2[w][0] - multi[w][0]))


    plt.xlim(0,1); plt.ylim(0,1)
    plt.scatter(a, b, marker = '.')
    plt.plot([0, 1], [0, 1], ls="-", c=".5")

    plt.xlabel('single')
    plt.ylabel('multi')
项目:code-uai16    作者:thanhan    | 项目源码 | 文件源码
def plot_gold(gold):
    #plt.xlim([0.2,1])
    #plt.ylim([0.7,1])
    x = []
    y = []
    for (wid,(sen, spe, n)) in gold.items():
      if wid.startswith('S'):
        x.append(sen)
        y.append(spe)
    plt.scatter(x,y, c = 'r', marker = 'o', label = 'Novice')

    x = []; y = []
    for (wid,(sen, spe, n)) in gold.items():
      if wid.startswith('E'):
        x.append(sen)
        y.append(spe)
    plt.scatter(x,y, c = 'b', marker = 'x', label = 'Expert')

    plt.legend(loc = 'lower left')
    plt.xlabel("Sensitivity")
    plt.ylabel("Specificity")
项目:photinia    作者:XoriieInpottn    | 项目源码 | 文件源码
def plot_with_labels(low_dim_embs, labels, filename='tsne.png'):
    assert low_dim_embs.shape[0] >= len(labels), "More labels than embeddings"
    plt.figure(figsize=(18, 18))  # in inches
    x = low_dim_embs[:, 0]
    y = low_dim_embs[:, 1]
    plt.scatter(x, y)
    for i, label in enumerate(labels):
        x, y = low_dim_embs[i, :]
        plt.annotate(label,
                     xy=(x, y),
                     xytext=(5, 2),
                     textcoords='offset points',
                     ha='right',
                     va='bottom')
    plt.show()
    # plt.savefig(filename)
项目:DenoiseAverage    作者:Pella86    | 项目源码 | 文件源码
def show_translation(self, dx, dy):
        ''' prints on the image where the peak is
        usage:
            corr = Corr()
            best = corr.find_peak()
            dx, dy = corr.find_translation(best)
            corr.show_image()
            corr.show_translation(dx, dy)
            plt.show()
        '''
        ody = dx + self.data.shape[0]/2
        odx = self.data.shape[1]/2 - dy
        plt.scatter(odx, ody, s=40, alpha = .5)    
        return odx, ody

#==============================================================================
# # Mask image Handling class
#==============================================================================
项目:Flavor-Network    作者:lingcheng99    | 项目源码 | 文件源码
def tsne_cluster_cuisine(df,sublist):
    lenlist=[0]
    df_sub = df[df['cuisine']==sublist[0]]
    lenlist.append(df_sub.shape[0])
    for cuisine in sublist[1:]:
        temp = df[df['cuisine']==cuisine]
        df_sub = pd.concat([df_sub, temp],axis=0,ignore_index=True)
        lenlist.append(df_sub.shape[0])
    df_X = df_sub.drop(['cuisine','recipeName'],axis=1)
    print df_X.shape, lenlist

    dist = squareform(pdist(df_X, metric='cosine'))
    tsne = TSNE(metric='precomputed').fit_transform(dist)

    palette = sns.color_palette("hls", len(sublist))
    plt.figure(figsize=(10,10))
    for i,cuisine in enumerate(sublist):
        plt.scatter(tsne[lenlist[i]:lenlist[i+1],0],\
        tsne[lenlist[i]:lenlist[i+1],1],c=palette[i],label=sublist[i])
    plt.legend()

#interactive plot with boken; set up for four categories, with color palette; pass in df for either ingredient or flavor
项目:KATE    作者:hugochan    | 项目源码 | 文件源码
def word_cloud(word_embedding_matrix, vocab, s, save_file='scatter.png'):
    words = [(i, vocab[i]) for i in s]
    model = TSNE(n_components=2, random_state=0)
    #Note that the following line might use a good chunk of RAM
    tsne_embedding = model.fit_transform(word_embedding_matrix)
    words_vectors = tsne_embedding[np.array([item[1] for item in words])]

    plt.subplots_adjust(bottom = 0.1)
    plt.scatter(
        words_vectors[:, 0], words_vectors[:, 1], marker='o', cmap=plt.get_cmap('Spectral'))

    for label, x, y in zip(s, words_vectors[:, 0], words_vectors[:, 1]):
        plt.annotate(
            label,
            xy=(x, y), xytext=(-20, 20),
            textcoords='offset points', ha='right', va='bottom',
            fontsize=20,
            # bbox=dict(boxstyle='round,pad=1.', fc='yellow', alpha=0.5),
            arrowprops=dict(arrowstyle = '<-', connectionstyle='arc3,rad=0')
            )
    plt.show()
    # plt.savefig(save_file)
项目:OpenTDA    作者:outlace    | 项目源码 | 文件源码
def drawComplex(origData, ripsComplex, axes=[-6,8,-6,6]):
  plt.clf()
  plt.axis(axes)
  plt.scatter(origData[:,0],origData[:,1]) #plotting just for clarity
  for i, txt in enumerate(origData):
      plt.annotate(i, (origData[i][0]+0.05, origData[i][1])) #add labels

  #add lines for edges
  for edge in [e for e in ripsComplex if len(e)==2]:
      #print(edge)
      pt1,pt2 = [origData[pt] for pt in [n for n in edge]]
      #plt.gca().add_line(plt.Line2D(pt1,pt2))
      line = plt.Polygon([pt1,pt2], closed=None, fill=None, edgecolor='r')
      plt.gca().add_line(line)

  #add triangles
  for triangle in [t for t in ripsComplex if len(t)==3]:
      pt1,pt2,pt3 = [origData[pt] for pt in [n for n in triangle]]
      line = plt.Polygon([pt1,pt2,pt3], closed=False, color="blue",alpha=0.3, fill=True, edgecolor=None)
      plt.gca().add_line(line)
  plt.show()
项目:OpenTDA    作者:outlace    | 项目源码 | 文件源码
def drawComplex(data, ph, axes=[-6, 8, -6, 6]):
    plt.clf()
    plt.axis(axes)  # axes = [x1, x2, y1, y2]
    plt.scatter(data[:, 0], data[:, 1])  # plotting just for clarity
    for i, txt in enumerate(data):
        plt.annotate(i, (data[i][0] + 0.05, data[i][1]))  # add labels

    # add lines for edges
    for edge in [e for e in ph.ripsComplex if len(e) == 2]:
        # print(edge)
        pt1, pt2 = [data[pt] for pt in [n for n in edge]]
        # plt.gca().add_line(plt.Line2D(pt1,pt2))
        line = plt.Polygon([pt1, pt2], closed=None, fill=None, edgecolor='r')
        plt.gca().add_line(line)

    # add triangles
    for triangle in [t for t in ph.ripsComplex if len(t) == 3]:
        pt1, pt2, pt3 = [data[pt] for pt in [n for n in triangle]]
        line = plt.Polygon([pt1, pt2, pt3], closed=False,
                           color="blue", alpha=0.3, fill=True, edgecolor=None)
        plt.gca().add_line(line)
    plt.show()
项目:OpenTDA    作者:outlace    | 项目源码 | 文件源码
def drawComplex(origData, ripsComplex, axes=[-6,8,-6,6]):
  plt.clf()
  plt.axis(axes)
  plt.scatter(origData[:,0],origData[:,1]) #plotting just for clarity
  for i, txt in enumerate(origData):
      plt.annotate(i, (origData[i][0]+0.05, origData[i][1])) #add labels

  #add lines for edges
  for edge in [e for e in ripsComplex if len(e)==2]:
      #print(edge)
      pt1,pt2 = [origData[pt] for pt in [n for n in edge]]
      #plt.gca().add_line(plt.Line2D(pt1,pt2))
      line = plt.Polygon([pt1,pt2], closed=None, fill=None, edgecolor='r')
      plt.gca().add_line(line)

  #add triangles
  for triangle in [t for t in ripsComplex if len(t)==3]:
      pt1,pt2,pt3 = [origData[pt] for pt in [n for n in triangle]]
      line = plt.Polygon([pt1,pt2,pt3], closed=False, color="blue",alpha=0.3, fill=True, edgecolor=None)
      plt.gca().add_line(line)
  plt.show()
项目:histwords    作者:williamleif    | 项目源码 | 文件源码
def plot_word_dist(info, words, start_year, end_year, one_minus=False, legend_loc='upper left'):
    colors = ['r', 'g', 'b', 'c', 'm', 'y', 'k']
    plot_info = {}
    for word in words:
        plot_info[word] = info[word]
    for title, data_dict in plot_info.iteritems():
        x = []; y = []
        for year, val in data_dict.iteritems():
            if year >= start_year and year <= end_year:
                x.append(year)
                if one_minus:
                    val = 1 - val
                y.append(val)
        color = colors.pop()
        plt.plot(x, smooth(np.array(y)), color=color)
        plt.scatter(x, y, marker='.', color=color)
    plt.legend(plot_info.keys(), loc=legend_loc)
    return plt
项目:histwords    作者:williamleif    | 项目源码 | 文件源码
def plot_word_basic(info, words, start_year, end_year, datatype):
    colors = ['r', 'g', 'b', 'c', 'm', 'y', 'k']
    plot_info = {}
    for word in words:
        plot_info[word] = info[word]
    for title, data_dict in plot_info.iteritems():
        x = []; y = []
        for year, val in data_dict[datatype].iteritems():
            if year >= start_year and year <= end_year:
                x.append(year)
                y.append(val)
        color = colors.pop()
        plt.plot(x, smooth(np.array(y)), color=color)
        plt.scatter(x, y, marker='.', color=color)
    plt.legend(plot_info.keys())
    plt.show()
项目:kmeans-service    作者:MAYHEM-Lab    | 项目源码 | 文件源码
def plot_spatial_cluster_fig(data, covar_type_tied_labels_k):
    """ Creates a 3x2 plot spatial plot using labels as the color """
    sns.set(context='talk', style='white')
    data.columns = [c.lower() for c in data.columns]
    fig = plt.figure()
    placement = {'full': {True: 1, False: 4}, 'diag': {True: 2, False: 5}, 'spher': {True: 3, False: 6}}

    lim_left = data['longitude'].min()
    lim_right = data['longitude'].max()
    lim_bottom = data['latitude'].min()
    lim_top = data['latitude'].max()
    for covar_type, covar_tied, labels, k in covar_type_tied_labels_k:
        plt.subplot(2, 3, placement[covar_type][covar_tied])
        plt.scatter(data['longitude'], data['latitude'], c=labels, cmap=plt.cm.rainbow, s=10)
        plt.xlim(left=lim_left, right=lim_right)
        plt.ylim(bottom=lim_bottom, top=lim_top)
        plt.xticks([])
        plt.yticks([])
        plt.xlabel('Longitude')
        plt.ylabel('Latitude')
        plt.title('{}-{}, K={}'.format(covar_type.capitalize(), ['Untied', 'Tied'][covar_tied], k))
    plt.tight_layout()
    return fig
项目:autonomio    作者:autonomio    | 项目源码 | 文件源码
def paramagg(data):

    '''
    USE: paramagg(df)

    Provides an overview in one plot for a parameter scan. Useful
    to understand rough distribution of accuracacy and loss for both
    test and train.

    data = a pandas dataframe from hyperscan()
    '''

    plt.figure(num=None, figsize=(8, 8), dpi=80, facecolor='w', edgecolor='k')

    plt.scatter(data.train_loss, data.train_acc, label='train')
    plt.scatter(data.test_loss, data.test_acc, label='test')

    plt.legend(loc='upper right')
    plt.tick_params(axis='both', which='major', pad=15)

    plt.xlabel('loss', fontsize=18, labelpad=15, color="gray")
    plt.ylabel('accuracy', fontsize=18, labelpad=15, color="gray")

    plt.show()
项目:em_examples    作者:geoscixyz    | 项目源码 | 文件源码
def addLayer2Mod(zcLayer,dzLayer,mod,sigLayer):

    CCLocs = mesh.gridCC

    zmax = zcLayer + dzLayer/2.
    zmin = zcLayer - dzLayer/2.

    belowInd = np.where(CCLocs[:,1] <= zmax)[0]
    aboveInd = np.where(CCLocs[:,1] >= zmin)[0]
    layerInds = list(set(belowInd).intersection(aboveInd))

    # # Check selected cell centers by plotting
    # fig = plt.figure()
    # ax = fig.add_subplot(111)
    # plt.scatter(CCLocs[layerInds,0],CCLocs[layerInds,1])
    # ax.set_xlim(-40,40)
    # ax.set_ylim(-35,0)
    # plt.axes().set_aspect('equal')
    # plt.show()

    mod[layerInds] = sigLayer
    return mod
项目:Supply-demand-forecasting    作者:LevinJ    | 项目源码 | 文件源码
def disp_gap_bytraffic(self):
        df = self.gapdf
        data_dir = g_singletonDataFilePath.getTrainDir()
        dumpfile_path = '../data_preprocessed/' + data_dir.split('/')[-2] + '_prevtraffic.df.pickle'
        dumpload = DumpLoad(dumpfile_path)
        if dumpload.isExisiting():
            temp_df = dumpload.load()
        else:
            traffic_dict = self.get_traffic_dict(data_dir)

            temp_df = self.X_y_Df[['start_district_id', 'time_slotid']].apply(self.find_prev_traffic,axis = 1, traffic_dict=traffic_dict, pre_num = 3)   
            dumpload.dump(temp_df)

        df = pd.concat([df, temp_df],  axis=1)


        by_traffic = df.groupby('traffic1')
        x=[]
        y=[]
        for name, group in by_traffic:
            x.append(name)
            y.append(group['gap'].mean())
        plt.scatter(x,y)

        return
项目:reconstruction    作者:microelly2    | 项目源码 | 文件源码
def showHeightMap(x,y,z,zi):
    ''' show height map in maptplotlib '''
    zi=zi.transpose()

    plt.imshow(zi, vmin=z.min(), vmax=z.max(), origin='lower',
               extent=[ y.min(), y.max(),x.min(), x.max()])

    plt.colorbar()

    CS = plt.contour(zi,15,linewidths=0.5,colors='k',
               extent=[ y.min(), y.max(),x.min(), x.max()])
    CS = plt.contourf(zi,15,cmap=plt.cm.rainbow, 
               extent=[ y.min(), y.max(),x.min(), x.max()])

    z=z.transpose()
    plt.scatter(y, x, c=z)

    # achsen umkehren
    #plt.gca().invert_xaxis()
    #plt.gca().invert_yaxis()

    plt.show()
    return
项目:DNGR-Keras    作者:MdAsifKhan    | 项目源码 | 文件源码
def cluster(data,true_labels,n_clusters=3):

    km = KMeans(init='k-means++', n_clusters=n_clusters, n_init=10)
    km.fit(data)

    km_means_labels = km.labels_
    km_means_cluster_centers = km.cluster_centers_
    km_means_labels_unique = np.unique(km_means_labels)

    colors_ = cycle(colors.cnames.keys())

    initial_dim = np.shape(data)[1]
    data_2 = tsne(data,2,initial_dim,30)

    plt.figure(figsize=(12, 6))
    plt.scatter(data_2[:,0],data_2[:,1], c=true_labels)
    plt.title('True Labels')

    return km_means_labels
项目:TickTickBacktest    作者:gavincyi    | 项目源码 | 文件源码
def plot_graph(cls, date_time, price, graph=None):
        """
        Plot the graph
        :param graph: MatPlotLibGraph
        :param date_time: Date time
        :param price: Price
        """
        date_time = (date_time - datetime.datetime(1970, 1, 1)).total_seconds()
        if graph is None:
            graph = plt.scatter([date_time], [price])
            plt.xlim([date_time, date_time + 60 * 60 * 24])
            # plt.ylim([float(price) * 0.95, float(price) * 1.05])
            plt.draw()
            plt.pause(0.1)
        else:
            array = graph.get_offsets()
            array = np.append(array, [date_time, price])
            graph.set_offsets(array)
            # plt.xlim([array[::2].min() - 0.5, array[::2].max() + 0.5])
            plt.ylim([float(array[1::2].min()) - 0.5, float(array[1::2].max()) + 0.5])
            plt.draw()
            plt.pause(0.1)

        return graph
项目:pyro    作者:uber    | 项目源码 | 文件源码
def plot_tsne(z_mu, classes, name):
    import numpy as np
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    from sklearn.manifold import TSNE
    model_tsne = TSNE(n_components=2, random_state=0)
    z_states = z_mu.data.cpu().numpy()
    z_embed = model_tsne.fit_transform(z_states)
    classes = classes.data.cpu().numpy()
    fig666 = plt.figure()
    for ic in range(10):
        ind_vec = np.zeros_like(classes)
        ind_vec[:, ic] = 1
        ind_class = classes[:, ic] == 1
        color = plt.cm.Set1(ic)
        plt.scatter(z_embed[ind_class, 0], z_embed[ind_class, 1], s=10, color=color)
        plt.title("Latent Variable T-SNE per Class")
        fig666.savefig('./vae_results/'+str(name)+'_embedding_'+str(ic)+'.png')
    fig666.savefig('./vae_results/'+str(name)+'_embedding.png')
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def draw(X, pred, means, covariances, output):
    xp = cupy.get_array_module(X)
    for i in six.moves.range(2):
        labels = X[pred == i]
        if xp is cupy:
            labels = labels.get()
        plt.scatter(labels[:, 0], labels[:, 1], c=np.random.rand(3))
    if xp is cupy:
        means = means.get()
        covariances = covariances.get()
    plt.scatter(means[:, 0], means[:, 1], s=120, marker='s', facecolors='y',
                edgecolors='k')
    x = np.linspace(-5, 5, 1000)
    y = np.linspace(-5, 5, 1000)
    X, Y = np.meshgrid(x, y)
    for i in six.moves.range(2):
        Z = mlab.bivariate_normal(X, Y, np.sqrt(covariances[i][0]),
                                  np.sqrt(covariances[i][1]),
                                  means[i][0], means[i][1])
        plt.contour(X, Y, Z)
    plt.savefig(output)
项目:HyperGAN    作者:255BITS    | 项目源码 | 文件源码
def sample(self, filename, save_samples):
        gan = self.gan
        generator = gan.generator.sample

        sess = gan.session
        config = gan.config
        x_v, z_v = sess.run([gan.inputs.x, gan.encoder.z])

        sample = sess.run(generator, {gan.inputs.x: x_v, gan.encoder.z: z_v})

        plt.clf()
        fig = plt.figure(figsize=(3,3))
        plt.scatter(*zip(*x_v), c='b')
        plt.scatter(*zip(*sample), c='r')
        plt.xlim([-2, 2])
        plt.ylim([-2, 2])
        plt.ylabel("z")
        fig.canvas.draw()
        data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
        data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
        #plt.savefig(filename)
        self.plot(data, filename, save_samples)
        return [{'image': filename, 'label': '2d'}]
项目:SlidingWindowVideoTDA    作者:ctralie    | 项目源码 | 文件源码
def plotDGM(dgm, color = 'b', sz = 20, label = 'dgm', axcolor = np.array([0.0, 0.0, 0.0]), marker = None):
    if dgm.size == 0:
        return
    # Create Lists
    # set axis values
    axMin = np.min(dgm)
    axMax = np.max(dgm)
    axRange = axMax-axMin
    a = max(axMin - axRange/5, 0)
    b = axMax+axRange/5
    # plot line
    plt.plot([a, b], [a, b], c = axcolor, label = 'none')
    plt.hold(True)
    # plot points
    if marker:
        H = plt.scatter(dgm[:, 0], dgm[:, 1], sz, color, marker, label=label, edgecolor = 'none')
    else:
        H = plt.scatter(dgm[:, 0], dgm[:, 1], sz, color, label=label, edgecolor = 'none')
    # add labels
    plt.xlabel('Time of Birth')
    plt.ylabel('Time of Death')
    return H
项目:dataScryer    作者:Griesbacher    | 项目源码 | 文件源码
def example_wiki():
    """
    Example based on: https://en.wikipedia.org/wiki/Simple_linear_regression#Numerical_example
    """
    data_x = [1.47, 1.50, 1.52, 1.55, 1.57, 1.60, 1.63, 1.65, 1.68, 1.70, 1.73, 1.75, 1.78, 1.80, 1.83]
    data_y = [52.21, 53.12, 54.48, 55.84, 57.20, 58.57, 59.93, 61.29, 63.11, 64.47, 66.28, 68.10, 69.92, 72.19, 74.46]
    data = list(zip(data_x, data_y))
    s = SimpleLinearRegression()
    start = 1.70
    forecast = s.calc_forecast({}, start, 0.3, 0.05, len(data), data)
    print(forecast)
    y = 80
    x = s.calc_intersection({}, start, 0.4, 0.05, len(data), data, y)
    print(x)
    try:
        import matplotlib.pyplot as plt
        plt.scatter(*zip(*data), label="v")
        plt.scatter(*zip(*forecast), label="f")
        plt.plot(start + x, y, 'x')
        plt.show()
    except:
        print("Could not print the example")
项目:dcss_single_cell    作者:srmcc    | 项目源码 | 文件源码
def plot_svd(sigma_full, sigma_dls, k, plot_loc):
    """ Plot the variance explained by different principal components
    :param n_components: Number of components to show the variance
    :param ylim: y-axis limits
    :param fig: matplotlib Figure object
    :param ax: matplotlib Axis object
    :return: fig, ax
    """
    fig, ax = plt.subplots()
    ax.scatter(range(len(sigma_full)),sigma_full,c='red',s=36,edgecolors='gray',
                    lw = 0.5, label='TCC singular values')
    ax.scatter(range(len(sigma_dls)),sigma_dls,c='blue',s=36,edgecolors='gray',
                    lw = 0.5, label='TCC_dls singular values')
    ax.legend(loc='upper right',bbox_to_anchor=(1.05, 1))
    ax.set_xlabel('Components')
    ax.set_ylabel('Singular Values')
    plt.title('TCC Distribution Singular Values')
    fig.tight_layout()
    plt.savefig(plot_loc+ 'plot_pca_variance_explained_' +str(k) +'.pdf')
项目:dcss_single_cell    作者:srmcc    | 项目源码 | 文件源码
def tru_plot9(X,labels,t,plot_suffix,clust_names,clust_color, plot_loc):
    """
    From clustering_on_transcript_compatibility_counts, see github for MIT license
    """
    unique_labels = np.unique(labels)
    plt.figure(figsize=(15,10))
    for i in unique_labels:
        ind = np.squeeze(labels == i)
        plt.scatter(X[ind,0],X[ind,1],c=clust_color[i],s=36,edgecolors='gray',
                    lw = 0.5, label=clust_names[i])        
    plt.legend(loc='upper right',bbox_to_anchor=(1.1, 1))
    plt.legend(loc='upper right',bbox_to_anchor=(1.19, 1.01))
    plt.title(t)
    plt.xlim([-20,20])
    plt.ylim([-20,20])
    plt.axis('off')
    plt.savefig(plot_loc+ 't-SNE_plot_tru_plot9_'+ plot_suffix +'.pdf', bbox_inches='tight')

    # Plot function with Zeisel's colors corresponding to labels
项目:uncover-ml    作者:GeoscienceAustralia    | 项目源码 | 文件源码
def create_scatter_plot(outfile_results, config):
    true_vs_pred = os.path.join(config.output_dir,
                                config.name + "_results.csv")
    true_vs_pred_plot = os.path.join(config.output_dir,
                                     config.name + "_results.png")
    with hdf.open_file(outfile_results, 'r') as f:
        prediction = f.get_node("/", "Prediction").read()
        y_true = f.get_node("/", "y_true").read()
        np.savetxt(true_vs_pred, X=np.vstack([y_true, prediction]).T,
                   delimiter=',')
        plt.figure()
        plt.scatter(y_true, prediction)
        plt.title('true vs prediction')
        plt.xlabel('True')
        plt.ylabel('Prediction')
        plt.savefig(true_vs_pred_plot)
项目:RecQ    作者:Coder-Yu    | 项目源码 | 文件源码
def scatter(x, y, color, title='',xLabel='',yLabel='',savePath='../visual/visualization/p2'):
        fig, ax1 = plt.subplots(1, 1, figsize=(8, 6), sharex=True)

        # sns.set(style="white")
        ax1.set_ylim(-10, max(y) + 20)
        ax1.set_xlim(-10, max(x) + 20)
        ax1.set_title(title, fontsize=20)
        ax1.set_xlabel(xLabel, fontsize=16)
        ax1.set_ylabel(yLabel, fontsize=16)
        ax1.tick_params(axis='x', labelsize=16)
        ax1.tick_params(axis='y', labelsize=16)
        plt.scatter(x, y, c=color, alpha=0.7, )
        plt.grid(True)
        plt.savefig(savePath,bbox_inches='tight')
        #plt.show()
        plt.close('all')
项目:ANN-PONR-Python3    作者:anon-42    | 项目源码 | 文件源码
def plot_output(self, outputneuron, inputMatrix, correctOutput,
                    points1=None, points2=None):
        ''' 
        Shows a plot which compares the desired (correct) Output with the
        actually output of a neuron.
        '''

        fig = plt.gcf()
        fig.canvas.set_window_title('Output')
        net_output = self.Net.forward(inputMatrix)
        x = np.arange(1, len(inputMatrix)+1)
        y = net_output[:, outputneuron-1]
        z = correctOutput[:, outputneuron-1]
        if not(points1 is None and points2 is None):
            points1 = np.arange(1, len(points1)+1)
            plt.scatter(points1, points2, 5, color='red')
        plt.plot(x, y, label='ANN output')
        plt.plot(x, z, label='Correct output')

        plt.xlabel('Pattern number')
        plt.ylabel('Output of neuron' + str(outputneuron))
        plt.legend(loc='lower left')
        plt.show()
项目:SciData_08-17-2017    作者:kitestring    | 项目源码 | 文件源码
def SimilarityPlot(self, SpectralDict):
        fig = plt.figure(figsize=(18,9))

        # Add each data set to the Spectral Qualithy Plot
        for n, data_set in enumerate(SpectralDict['data_sets']):
            plt.scatter(SpectralDict['x_data'][n], SpectralDict['y_data'][n], color=self.color_codes[n], label=data_set)

        # Horizontal 800 Similarity line
        plt.axhline(y=800, xmin=0, xmax=1, hold=None, color=self.red_hex_code, label='800 Similarity')

        # Make your plot pretty
        plt.legend(loc='upper left')
        plt.ylabel('Similarity vs. Main NIST Hit')
        plt.xlabel('Concentration (pg)')
        plt.title('%s - Spectral Quality' % SpectralDict['analyte_name'])
        plt.xscale('log')
        plt.xlim(SpectralDict['x_axis_min'], SpectralDict['x_axis_max'])
        plt.savefig(SpectralDict['file_name'], bbox_inches='tight')
项目:DHP    作者:YuhangSong    | 项目源码 | 文件源码
def log_thread_step(self):
        '''log_scan_path'''
        if self.if_log_scan_path:
            plt.figure(str(self.env_id)+'_scan_path')
            plt.scatter(self.cur_lon, self.cur_lat, c='r')
            plt.scatter(-180, -90)
            plt.scatter(-180, 90)
            plt.scatter(180, -90)
            plt.scatter(180, 90)
            plt.pause(0.00001)

        if self.if_log_cc:
            if self.mode is 'off_line':
                self.agent_result_saver += [copy.deepcopy(fixation2salmap(fixation=[[self.cur_lon,self.cur_lon]],
                                                                          mapwidth=self.heatmap_width,
                                                                          mapheight=self.heatmap_height))]
            elif self.mode is 'on_line':
                print('not implement')
                import sys
                sys.exit(0)
项目:spot-price-reporter    作者:EntilZha    | 项目源码 | 文件源码
def create_plot(json_data, output):
    all_data = pd.DataFrame(json_data)
    df = all_data[all_data['ProductDescription'] == 'Linux/UNIX']
    df = df.drop_duplicates(subset=['DateTime', 'AvailabilityZone', 'InstanceType'])
    x_min = df['DateTime'].min()
    x_max = df['DateTime'].max()
    border_pad = (x_max - x_min) * 5 / 100

    g = sns.FacetGrid(
        df,
        col='InstanceType',
        hue='AvailabilityZone',
        xlim=(x_min - border_pad, x_max + border_pad),
        legend_out=True,
        size=10,
        palette="Set1"
    )
    g.map(plt.scatter, 'DateTime', 'SpotPrice', s=4).add_legend()
    plt.subplots_adjust(top=.9)
    g.fig.suptitle('AWS Spot Prices between {start} and {end}'.format(start=x_min, end=x_max))
    g.savefig(output, format='png')
项目:Machine-Learning-Algorithms    作者:PacktPublishing    | 项目源码 | 文件源码
def show_classification_areas(X, Y, lr):
    x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
    y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
    xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.02), np.arange(y_min, y_max, 0.02))
    Z = lr.predict(np.c_[xx.ravel(), yy.ravel()])

    Z = Z.reshape(xx.shape)
    plt.figure(1, figsize=(30, 25))
    plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Pastel1)

    # Plot also the training points
    plt.scatter(X[:, 0], X[:, 1], c=np.abs(Y - 1), edgecolors='k', cmap=plt.cm.coolwarm)
    plt.xlabel('X')
    plt.ylabel('Y')

    plt.xlim(xx.min(), xx.max())
    plt.ylim(yy.min(), yy.max())
    plt.xticks(())
    plt.yticks(())

    plt.show()
项目:2020plus    作者:KarchinLab    | 项目源码 | 文件源码
def correlation_plot(x, y,
                     save_path,
                     title,
                     xlabel, ylabel):
    plt.scatter(x, y)
    slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
    line_x = np.arange(x.min(), x.max())
    line_y = slope*line_x + intercept
    plt.plot(line_x, line_y,
             label='$%.2fx + %.2f$, $R^2=%.2f$' % (slope, intercept, r_value**2))
    plt.legend(loc='best')
    plt.title(title)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.tight_layout()
    plt.savefig(save_path)
    plt.clf()  # clear figure
    plt.close()
项目:ML-From-Scratch    作者:eriklindernoren    | 项目源码 | 文件源码
def _calculate_scatter_matrices(self, X, y):
        n_features = np.shape(X)[1]
        labels = np.unique(y)

        # Within class scatter matrix:
        # SW = sum{ (X_for_class - mean_of_X_for_class)^2 }
        #   <=> (n_samples_X_for_class - 1) * covar(X_for_class)
        SW = np.empty((n_features, n_features))
        for label in labels:
            _X = X[y == label]
            SW += (len(_X) - 1) * calculate_covariance_matrix(_X)

        # Between class scatter:
        # SB = sum{ n_samples_for_class * (mean_for_class - total_mean)^2 }
        total_mean = np.mean(X, axis=0)
        SB = np.empty((n_features, n_features))
        for label in labels:
            _X = X[y == label]
            _mean = np.mean(_X, axis=0)
            SB += len(_X) * (_mean - total_mean).dot((_mean - total_mean).T)

        return SW, SB
项目:FFS-ANN    作者:GVLABHernandez    | 项目源码 | 文件源码
def scatter_regresion_Plot(X, Y, testName):

    plt.scatter(X, Y, c = 'b', label = '_nolegend_', s = 1)

    X = X.reshape(-1, 1)
    Y = Y.reshape(-1, 1)
    R2 = r2_score(X, Y)

    regr = linear_model.LinearRegression()
    regr.fit(X, Y)
    plt.plot(X, regr.predict(X), "--", label = 'Regression', color = 'r')
    plt.title(testName + ' ($R^2$: ' + "{0:.3f}".format(R2) + ")", fontsize = 14)
    plt.xlabel('True Values', fontsize = 12, weight = 'bold')
    plt.ylabel('Predicted Values', fontsize = 12, weight = 'bold')
    plt.legend(loc = 'upper left', bbox_to_anchor = (0, 1.0), fancybox = True, shadow = True, fontsize = 10)
    plt.subplots_adjust(left = 0.2, right = 0.9, bottom = 0.05, top = 0.97, wspace = 0.15, hspace = 0.3)
项目:PengjuStock    作者:dadatou20089    | 项目源码 | 文件源码
def plot_decision_boundary(X, Y, model):
    # X - some data in 2dimensional np.array
    x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
    y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
    xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.01),
                         np.arange(y_min, y_max, 0.01))

    # here "model" is your model's prediction (classification) function
    Z = model(np.c_[xx.ravel(), yy.ravel()])

    # Put the result into a color plot
    Z = Z.reshape(xx.shape)
    plt.contourf(xx, yy, Z, cmap=plt.cm.Paired)
    plt.axis('off')

    for i in x:
        print i

    # Plot also the training points
    plt.scatter(X[:, 0], X[:, 1], c=Y, cmap=plt.cm.Paired)


#???????
项目:miccai-2016-surgical-activity-rec    作者:rdipietro    | 项目源码 | 文件源码
def plot_label_seq(label_seq, num_classes, y_value):
    """ Plot a label sequence.

    The sequence will be shown using a horizontal colored line, with colors
    corresponding to classes.

    Args:
        label_seq: An int NumPy array with shape `[duration, 1]`.
        num_classes: An integer.
        y_value: A float. The y value at which the horizontal line will sit.
    """

    label_seq = label_seq.flatten()
    x = np.arange(0, label_seq.size)
    y = y_value*np.ones(label_seq.size)
    plt.scatter(x, y, c=label_seq, marker='|', lw=2, vmin=0, vmax=num_classes)
项目:DeepLearning    作者:Wanwannodao    | 项目源码 | 文件源码
def plot(data, dec, filename="data.png"):
    idx    = dec[ np.where(dec != 51)[0] ]
    convex = data[idx, :] 

    x = data[1:, 0]
    y = data[1:, 1]
    convex_x = convex[1:, 0]
    convex_y = convex[1:, 1]

    plt.scatter(x, y)
    plt.plot(convex_x, convex_y, color="orange")
    plt.xlim(0.0, 1.0)
    plt.ylim(0.0, 1.0)
    plt.savefig(filename)

    plt.clf()
    plt.close()
项目:LensCalibrator    作者:1024jp    | 项目源码 | 文件源码
def show_map(self):
        interval = 200
        size = self.image_size
        w, h = np.meshgrid(range(0, size[0], interval),
                           range(0, size[1], interval))
        points = np.vstack((w.flatten(), h.flatten())).T.astype('float32')
        new_points = self.calibrate_points(points)

        plt.scatter(points[:, 0], points[:, 1], 20, 'b', alpha=.5)
        plt.scatter(new_points[:, 0], new_points[:, 1], 20, 'r', alpha=.5)

        plt.axes().set_aspect('equal', 'datalim')
        plt.show()
项目:CausalGAN    作者:mkocaoglu    | 项目源码 | 文件源码
def record_scatter(self,sess):
        Xg=sess.run(self.gen.X,{self.gen.N:5000})
        X1,X2,X3=np.split(Xg,3,axis=1)
        x1x2,x1x3,x2x3 = summary_scatterplots(X1,X2,X3)
        step,Pg_summ=sess.run([self.step,self.g_scatter_summary],{self.tf_scatter:np.concatenate([x1x2,x1x3,x2x3])})
        self.summary_writer.add_summary(Pg_summ,step)
        self.summary_writer.flush()

#        if self.config.save_pdfs:
#            self.save_np_scatter(step,X1,X3)

#Maybe it's the supervisor creating the segfault??
#Try just one model at a time

#   #will cause segfault ;)
#    def save_np_scatter(self,step,x,y,save_dir=None,ext='.pdf'):
#        '''
#        This is a convenience that just saves the image as a pdf in addition to putting it on
#        tensorboard. only does x1x3 because that's what I needed at the moment
#
#        sorry I wrote this really quickly
#        TODO: make less bad.
#        '''
#        plt.scatter(x,y)
#        plt.title('X1X3')
#        plt.xlabel('X1')
#        plt.ylabel('X3')
#        plt.xlim([0,1])
#        plt.ylim([0,1])
#
#        scatter_dir=os.path.join(self.model_dir,'scatter')
#
#        save_dir=save_dir or scatter_dir
#        if not os.path.exists(save_dir):
#            os.mkdir(save_dir)
#
#        save_name=os.path.join(save_dir,'{}_scatter_x1x3_{}_{}'+ext)
#        save_path=save_name.format(step,self.config.data_type,self.gan_type)
#
#        plt.savefig(save_path)
项目:CausalGAN    作者:mkocaoglu    | 项目源码 | 文件源码
def summary_scatterplots(X1,X2,X3):
    with tf.name_scope('scatter'):
        img1=summary_scatter2d(X1,X2,'X1X2',xlabel='X1',ylabel='X2')
        img2=summary_scatter2d(X1,X3,'X1X3',xlabel='X1',ylabel='X3')
        img3=summary_scatter2d(X2,X3,'X2X3',xlabel='X2',ylabel='X3')
        plt.close()
    return img1,img2,img3
项目:kaggle-review    作者:daxiongshu    | 项目源码 | 文件源码
def scatter(x,y,xlabel='x',ylabel='y',title=None,line=False,name=None,show=False):
    sns.set()
    title = "%s vs %s"%(xlabel,ylabel) if title is None else title
    plt.scatter(x,y)
    if line:
        plt.plot(x,y)
    plt.title(title)
    plt.ylabel('y: %s'%ylabel)
    plt.xlabel('x: %s'%xlabel)
    if name is not None:
        #fig = plt.Figure()
        plt.savefig(name)
    if show:
        plt.show()
    plt.clf()
项目:SWEETer-Cat    作者:DanielAndreasen    | 项目源码 | 文件源码
def plot(x, y):
    plt.scatter(x, y, alpha=0.7)
    plt.tight_layout()
    plt.show()
项目:KATE    作者:hugochan    | 项目源码 | 文件源码
def plot_tsne_3d(doc_codes, doc_labels, classes_to_visual, save_file, maker_size=None, opaque=None):
    markers = ["D", "p", "*", "s", "d", "8", "^", "H", "v", ">", "<", "h", "|"]
    plt.rc('legend',**{'fontsize':20})
    colors = ['r', 'b', 'g', 'c', 'm', 'y', 'k']
    C = len(classes_to_visual)
    while True:
        if C <= len(markers):
            break
        markers += markers
    while True:
        if C <= len(colors):
            break
        colors += colors

    class_ids = dict(zip(classes_to_visual, range(C)))

    if isinstance(doc_codes, dict) and isinstance(doc_labels, dict):
        codes, labels = zip(*[(code, doc_labels[doc]) for doc, code in doc_codes.items() if doc_labels[doc] in classes_to_visual])
    else:
        codes, labels = doc_codes, doc_labels

    X = np.r_[list(codes)]
    tsne = TSNE(perplexity=30, n_components=3, init='pca', n_iter=5000)
    np.set_printoptions(suppress=True)
    X = tsne.fit_transform(X)

    fig = plt.figure(figsize=(10, 10), facecolor='white')
    ax = fig.add_subplot(111, projection='3d')

    # The problem is that the legend function don't support the type returned by a 3D scatter.
    # So you have to create a "dummy plot" with the same characteristics and put those in the legend.
    scatter_proxy = []
    for i in range(C):
        cls = classes_to_visual[i]
        idx = np.array(labels) == cls
        ax.scatter(X[idx, 0], X[idx, 1], X[idx, 2], c=colors[i], alpha=opaque[i] if opaque else 1, s=maker_size[i] if maker_size else 20, marker=markers[i], label=cls)
        scatter_proxy.append(mpl.lines.Line2D([0],[0], linestyle="none", c=colors[i], marker=markers[i], label=cls))
    ax.legend(scatter_proxy, classes_to_visual, numpoints=1)
    plt.savefig(save_file)
    plt.show()
项目:MulensModel    作者:rpoleski    | 项目源码 | 文件源码
def plot(self, n_points=5000, **kwargs):
        """
        Plots the caustics (using matplotlib.pyplot.scatter()).

        Parameters:
            n_points : *int*, optional
                The number of points to calculate along the caustic.
            ``**kwargs``
                keywords accepted by *matplotlib.pyplot.scatter()*
        """
        if self._x is None:
            self._calculate(n_points=n_points)
        pl.scatter(self._x, self._y, **kwargs)