当前位置: 首页>>代码示例>>Python>>正文


Python pyplot.annotate方法代码示例

本文整理汇总了Python中matplotlib.pyplot.annotate方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.annotate方法的具体用法?Python pyplot.annotate怎么用?Python pyplot.annotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.pyplot的用法示例。


在下文中一共展示了pyplot.annotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visualize_2D_trip

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def visualize_2D_trip(self,trip,tw_open,tw_close):
        plt.figure(figsize=(30,30))
        rcParams.update({'font.size': 22})
        # Plot cities
        colors = ['red'] # Depot is first city
        for i in range(len(tw_open)-1):
            colors.append('blue')
        plt.scatter(trip[:,0], trip[:,1], color=colors, s=200)
        # Plot tour
        tour=np.array(list(range(len(trip))) + [0])
        X = trip[tour, 0]
        Y = trip[tour, 1]
        plt.plot(X, Y,"--", markersize=100)
        # Annotate cities with TW
        tw_open = np.rint(tw_open)
        tw_close = np.rint(tw_close)
        time_window = np.concatenate((tw_open,tw_close),axis=1)
        for tw, (x, y) in zip(time_window,(zip(X,Y))):
            plt.annotate(tw,xy=(x, y))  
        plt.xlim(0,60)
        plt.ylim(0,60)
        plt.show()


    # Heatmap of permutations (x=cities; y=steps) 
开发者ID:MichelDeudon,项目名称:neural-combinatorial-optimization-rl-tensorflow,代码行数:27,代码来源:dataset.py

示例2: visualize_2D_trip

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def visualize_2D_trip(self, trip):
        plt.figure(figsize=(30,30))
        rcParams.update({'font.size': 22})

        # Plot cities
        plt.scatter(trip[:,0], trip[:,1], s=200)

        # Plot tour
        tour=np.array(list(range(len(trip))) + [0])
        X = trip[tour, 0]
        Y = trip[tour, 1]
        plt.plot(X, Y,"--", markersize=100)

        # Annotate cities with order
        labels = range(len(trip))
        for i, (x, y) in zip(labels,(zip(X,Y))):
            plt.annotate(i,xy=(x, y))  

        plt.xlim(0,100)
        plt.ylim(0,100)
        plt.show()


    # Heatmap of permutations (x=cities; y=steps) 
开发者ID:MichelDeudon,项目名称:neural-combinatorial-optimization-rl-tensorflow,代码行数:26,代码来源:dataset.py

示例3: plot_ours_mean

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def plot_ours_mean(measures_readers, metric, color, show_ids):
    if not show_ids:
        show_ids = []
    ops = []
    for first, measures_reader in flag_first_iter(measures_readers):
        this_op_bpps = []
        this_op_values = []
        for img_name, bpp, value in measures_reader.iter_metric(metric):
            this_op_bpps.append(bpp)
            this_op_values.append(value)
        ours_mean_bpp, ours_mean_value = np.mean(this_op_bpps), np.mean(this_op_values)
        ops.append((ours_mean_bpp, ours_mean_value))
        plt.scatter(ours_mean_bpp, ours_mean_value, marker='x', zorder=10, color=color,
                    label='Ours' if first else None)
    for (bpp, value), job_id in zip(sorted(ops), show_ids):
        plt.annotate(job_id, (bpp + 0.04, value),
                     horizontalalignment='bottom', verticalalignment='center') 
开发者ID:fab-jul,项目名称:imgcomp-cvpr,代码行数:19,代码来源:plotter.py

示例4: plot

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def plot(self, line_width=1, point_radius=math.sqrt(2.0), annotation_size=8, dpi=120, save=True, name=None):
        x = [self.nodes[i][0] for i in self.global_best_tour]
        x.append(x[0])
        y = [self.nodes[i][1] for i in self.global_best_tour]
        y.append(y[0])
        plt.plot(x, y, linewidth=line_width)
        plt.scatter(x, y, s=math.pi * (point_radius ** 2.0))
        plt.title(self.mode)
        for i in self.global_best_tour:
            plt.annotate(self.labels[i], self.nodes[i], size=annotation_size)
        if save:
            if name is None:
                name = '{0}.png'.format(self.mode)
            plt.savefig(name, dpi=dpi)
        plt.show()
        plt.gcf().clear() 
开发者ID:rochakgupta,项目名称:aco-tsp,代码行数:18,代码来源:aco_tsp.py

示例5: drawComplex

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
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() 
开发者ID:outlace,项目名称:OpenTDA,代码行数:24,代码来源:plotting.py

示例6: drawComplex

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
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() 
开发者ID:outlace,项目名称:OpenTDA,代码行数:23,代码来源:SimplicialComplex.py

示例7: projection

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def projection(embeddings, token_list):
    for k in range(6):
        embeddings=np.concatenate((embeddings, embeddings), axis=0)
    proj = PCA(embeddings)
    PCA_proj=proj.Y
    print PCA_proj.shape
    
    #plotting words within the 2D space of the two principal components:
    list=token_list[0]
    
        
    for n in range(maxlen):
        plt.plot(PCA_proj[n][0]+1,PCA_proj[n][1], 'w.')
        plt.annotate(list[n], xy=(PCA_proj[n][0],PCA_proj[n][1]), xytext=(PCA_proj[n][0],PCA_proj[n][1]))
    plt.show()       
    plt.ishold()
    
  
    return 
开发者ID:oswaldoludwig,项目名称:visually-informed-embedding-of-word-VIEW-,代码行数:21,代码来源:PCA_projection_1.01.py

示例8: main

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def main():
    args = parse_args()
    X, labels = np.loadtxt(args.embeddings_path), np.loadtxt(args.labels_path, dtype=np.str)
    tsne = TSNE(n_components=2, n_iter=10000, perplexity=5, init='pca', learning_rate=200, verbose=1)
    transformed = tsne.fit_transform(X)

    y = set(labels)
    labels = np.array(labels)
    plt.figure(figsize=(20, 14))
    colors = cm.rainbow(np.linspace(0, 1, len(y)))
    for label, color in zip(y, colors):
        points = transformed[labels == label, :]
        plt.scatter(points[:, 0], points[:, 1], c=[color], label=label, s=200, alpha=0.5)
        for p1, p2 in random.sample(list(zip(points[:, 0], points[:, 1])), k=min(1, len(points))):
            plt.annotate(label, (p1, p2), fontsize=30)

    plt.savefig('tsne_visualization.png', transparent=True, bbox_inches='tight', pad_inches=0)
    plt.show() 
开发者ID:arsfutura,项目名称:face-recognition,代码行数:20,代码来源:tsne_visualization.py

示例9: plot_embedding

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def plot_embedding(embedding, annotation=None, filename='outputs/embedding.png'):
    reduced = TSNE(n_components=2).fit_transform(embedding)
    plt.figure(figsize=(20, 20))
    max_x = np.amax(reduced, axis=0)[0]
    max_y = np.amax(reduced, axis=0)[1]
    plt.xlim((-max_x, max_x))
    plt.ylim((-max_y, max_y))

    plt.scatter(reduced[:, 0], reduced[:, 1], s=20, c=["r"] + ["b"] * (len(reduced) - 1))

    # Annotation
    if annotation:
        for i in range(embedding.shape[0]):
            target = annotation[i]
            x = reduced[i, 0]
            y = reduced[i, 1]
            plt.annotate(target, (x, y))

    plt.savefig(filename)
    # plt.show() 
开发者ID:andabi,项目名称:voice-vector,代码行数:22,代码来源:embedding.py

示例10: plot_accuracies

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def plot_accuracies(train_accuracies, dev_accuracies,opts):
    plt.figure(figsize=(6,4))
    plt.title(r"Learning Curve Accuracies of %s on train/dev set" % opts.model)
    plt.xlabel("SGD Iterations");plt.ylabel(r"Accuracy");
    plt.ylim(ymin=min(min(train_accuracies)*0.8, min(dev_accuracies)*0.8),ymax=max(1.2*max(train_accuracies), 1.2*max(dev_accuracies)))
    plt.plot(np.arange(opts.epochs),train_accuracies, color='b', marker='o', linestyle='-')
    plt.annotate("train curve",xy=(1,train_accuracies[1]),
                 xytext=(1,train_accuracies[1]+0.3),
                 arrowprops=dict(facecolor='green'),
                 horizontalalignment='left',verticalalignment='top')
    
    plt.plot(np.arange(opts.epochs),dev_accuracies, color='r', marker='o', linestyle='-')
    plt.annotate("dev curve",xy=(45,dev_accuracies[45]),
                 xytext=(45,dev_accuracies[45]+0.3),
                 arrowprops=dict(facecolor='red'),
                 horizontalalignment='left',verticalalignment='top')
    plt.savefig("./figures/%s/%s_learningCurve_on_train_dev_set_%d_epochs.png" % (opts.model,opts.model,opts.epochs))
    plt.show()
    plt.close() 
开发者ID:PDFangeltop1,项目名称:cs224d,代码行数:21,代码来源:runNNet.py

示例11: plot_cost

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def plot_cost(train_cost, dev_cost,opts):
    plt.figure(figsize=(6,4))
    plt.title(r"Learning Curve Cost of %s on train/dev set" % opts.model)
    plt.xlabel("SGD Iterations");plt.ylabel(r"Cost");
    plt.ylim(ymin=min(min(train_cost)*0.8, min(dev_cost)*0.8),ymax=max(1.2*max(train_cost), 1.2*max(dev_cost)))
    plt.plot(np.arange(opts.epochs),train_cost, color='b', marker='o', linestyle='-')
    plt.annotate("train curve",xy=(1,train_cost[1]),
                 xytext=(1,train_cost[1]+3),
                 arrowprops=dict(facecolor='green'),
                 horizontalalignment='left',verticalalignment='top')
    
    plt.plot(np.arange(opts.epochs),dev_cost, color='r', marker='o', linestyle='-')
    plt.annotate("dev curve",xy=(45,dev_cost[45]),
                 xytext=(45,dev_cost[45]+3),
                 arrowprops=dict(facecolor='red'),
                 horizontalalignment='left',verticalalignment='top')
    plt.savefig("./figures/%s/%s_learningCurveCost_on_train_dev_set_%d_epochs.png" % (opts.model,opts.model,opts.epochs))
    plt.show()
    plt.close() 
开发者ID:PDFangeltop1,项目名称:cs224d,代码行数:21,代码来源:runNNet.py

示例12: plot_cost_acc

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def plot_cost_acc(a, b, figname, epochs):
    annotate_size = 0.15
    if figname.startswith('Cost') == True:
        annotate_size *= 30
    
    plt.figure(figsize=(6,4))
    plt.title(figname)
    plt.xlabel("SGD Iterations");plt.ylabel(r"Accuracy or Cost")
    plt.ylim(ymin=min(min(a),min(b))*0.8,ymax=max(max(a),max(b))*1.2)
    plt.plot(np.arange(epochs),a,'bo-')
    plt.annotate("train_curve", xy=(1,a[1]),
                 xytext=(1,a[1]+annotate_size),
                 arrowprops=dict(facecolor='green'),
                 horizontalalignment='left',verticalalignment='top')

    plt.plot(np.arange(epochs),b,'ro-')
    plt.annotate("dev_curve",xy=(50,b[50]),
                 xytext=(50,b[50]+annotate_size),
                 arrowprops=dict(facecolor='red'),
                 horizontalalignment='left',verticalalignment='top')
    plt.savefig("%s_per_epochs.png"%figname)
    plt.close() 
开发者ID:PDFangeltop1,项目名称:cs224d,代码行数:24,代码来源:runNNet_dev_wvecDim.py

示例13: annotate_frequency_axis

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def annotate_frequency_axis(mark_freq, label_position_y=1, arrow_length=3, log_y=False, freq_range=None):#{{{
    """
    """
    import matplotlib.pyplot as plt
    if type(mark_freq) in (float,int): mark_freq=list(mark_freq,)
    if type(mark_freq) in (list,tuple): mark_freq=dict(zip(mark_freq,['' for mf in mark_freq]))
    for mfreq, mfreqtxt in mark_freq.items(): 
        label_y2 = label_position_y
        while (mfreqtxt[0:1]==' ' and mfreqtxt[-2:-1]==' '): 
            label_y2 = label_y2*2 if log_y else label_y2+1
            mfreqtxt=mfreqtxt[1:-1]; 
        bboxprops   = dict(boxstyle='round, pad=.15', fc='white', alpha=1, lw=0)
        arrowprops  = dict(arrowstyle=('->', '-|>', 'simple', 'fancy')[0], connectionstyle = 'arc3,rad=0', lw=1, ec='k', fc='w')
        if not freq_range  or  (mfreq > freq_range[0] and mfreq < freq_range[1]):
            plt.annotate(mfreqtxt,                    clip_on=True,
                    xy      = (mfreq, label_y2),    xycoords  ='data',
                    # (delete following line if text without arrow is used)
                    xytext  = (mfreq, label_y2*arrow_length if log_y else label_y+arrow_length),  textcoords='data',        
                    ha='center', va='bottom', size=15, color='k',
                    bbox        = bboxprops,        # comment out to disable bounding box
                    arrowprops  = arrowprops,       # comment out to disable arrow
                    )
#}}} 
开发者ID:FilipDominec,项目名称:python-meep-utils,代码行数:25,代码来源:meep_utils.py

示例14: visualize_joints_2d

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def visualize_joints_2d(
    ax, joints, joint_idxs=True, links=None, alpha=1, scatter=True, linewidth=2
):
    if links is None:
        links = [
            (0, 1, 2, 3, 4),
            (0, 5, 6, 7, 8),
            (0, 9, 10, 11, 12),
            (0, 13, 14, 15, 16),
            (0, 17, 18, 19, 20),
        ]
    # Scatter hand joints on image
    x = joints[:, 0]
    y = joints[:, 1]
    if scatter:
        ax.scatter(x, y, 1, "r")

    # Add idx labels to joints
    for row_idx, row in enumerate(joints):
        if joint_idxs:
            plt.annotate(str(row_idx), (row[0], row[1]))
    _draw2djoints(ax, joints, links, alpha=alpha, linewidth=linewidth)
    ax.axis("equal") 
开发者ID:hassony2,项目名称:obman_train,代码行数:25,代码来源:viz2d.py

示例15: main

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import annotate [as 别名]
def main():
  train_date = None
  tickers, periods, targets = parse_command_line(default_tickers=['BTC_ETH', 'BTC_LTC'],
                                                 default_periods=['day'],
                                                 default_targets=['high'])

  for ticker in tickers:
    for period in periods:
      for target in targets:
        job = JobInfo('_data', '_zoo', name='%s_%s' % (ticker, period), target=target)
        result_df = predict_multiple(job, raw_df=read_df(job.get_source_name()), rows_to_predict=120)
        result_df.index.names = ['']
        result_df.plot(title=job.name)

        if train_date is not None:
          x = train_date
          y = result_df['True'].min()
          plt.axvline(x, color='k', linestyle='--')
          plt.annotate('Training stop', xy=(x, y), xytext=(result_df.index.min(), y), color='k',
                       arrowprops={'arrowstyle': '->', 'connectionstyle': 'arc3', 'color': 'k'})

  plt.show() 
开发者ID:maxim5,项目名称:time-series-machine-learning,代码行数:24,代码来源:run_visual.py


注:本文中的matplotlib.pyplot.annotate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。