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


Python pyplot.arrow方法代码示例

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


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

示例1: plot2d

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def plot2d(self,ix=0,iy=1,clf=True):
        """
        Generates a 2-dimensional plot of the data set and principle components
        using matplotlib.

        ix specifies which p-dimension to put on the x-axis of the plot
        and iy specifies which to put on the y-axis (0-indexed)
        """
        import matplotlib.pyplot as plt
        x,y=self.N[:,ix],self.N[:,iy]
        if clf:
            plt.clf()
        plt.scatter(x,y)
        vals,evs=self.getEigensystem()
        #evx,evy=evs[:,ix],evs[:,iy]
        xl,xu=plt.xlim()
        yl,yu=plt.ylim()
        dx,dy=(xu-xl),(yu-yl)
        for val,vec,c in zip(vals,evs.T,self._colors):
            plt.arrow(0,0,val*vec[ix],val*vec[iy],head_width=0.05*(dx*dy/4)**0.5,fc=c,ec=c)
        #plt.arrow(0,0,vals[ix]*evs[ix,ix],vals[ix]*evs[iy,ix],head_width=0.05*(dx*dy/4)**0.5,fc='g',ec='g')
        #plt.arrow(0,0,vals[iy]*evs[ix,iy],vals[iy]*evs[iy,iy],head_width=0.05*(dx*dy/4)**0.5,fc='r',ec='r')
        if self.names is not None:
            plt.xlabel('$'+self.names[ix]+'/\\sigma$')
            plt.ylabel('$'+self.names[iy]+'/\\sigma$') 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:pca.py

示例2: poly_plot

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def poly_plot(xy, titlestr = "", margin = 0.25):
    """
        Plots polygon. For arrow see:
        http://matplotlib.org/examples/pylab_examples/arrow_simple_demo.html
        x = xy[:,0], y = xy[:,1]
    """
    xmin = np.min(xy[:,0])
    xmax = np.max(xy[:,0])
    ymin = np.min(xy[:,1])
    ymax = np.max(xy[:,1])
    hl = 0.1
    l = len(xy)
    for i in range(l):
        j = (i+1)%l  # keep index in [0,l)
        dx = xy[j,0] - xy[i,0]
        dy = xy[j,1] - xy[i,1]
        dd = np.sqrt(dx*dx + dy*dy)
        dx *= (1 - hl/dd)
        dy *= (1 - hl/dd)
        plt.arrow(xy[i,0], xy[i,1], dx, dy, head_width=0.05, head_length=0.1, fc='b', ec='b')
        plt.xlim(xmin-margin, xmax+margin)
        plt.ylim(ymin-margin, ymax+margin)
    plt.title(titlestr) 
开发者ID:Kirubaharan,项目名称:hydrology,代码行数:25,代码来源:ch_591_stage_area.py

示例3: plot

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def plot(self, linewidth=None, linestyle='-',
             startarrows=True, endarrows=True):
        """Plots the field line and arrows."""

        if linewidth is None:
            linewidth = matplotlib.rcParams['lines.linewidth']

        x, y = zip(*self.x)
        pyplot.plot(x, y, '-k', linewidth=linewidth, linestyle=linestyle)

        n = int(len(x)/2) if len(x) < 225 else 75
        if startarrows:
            pyplot.arrow(x[n], y[n], (x[n+1]-x[n])/100., (y[n+1]-y[n])/100.,
                         fc="k", ec="k",
                         head_width=0.1*linewidth, head_length=0.1*linewidth)

        if len(x) < 225 or not endarrows:
            return

        pyplot.arrow(x[-n], y[-n],
                     (x[-n+1]-x[-n])/100., (y[-n+1]-y[-n])/100.,
                     fc="k", ec="k",
                     head_width=0.1*linewidth, head_length=0.1*linewidth) 
开发者ID:tomduck,项目名称:electrostatics,代码行数:25,代码来源:electrostatics.py

示例4: plot_cell_transitions

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def plot_cell_transitions(self, cell_ix: int=0, alpha: float=0.1, alpha_neigh: float=0.2,
                              cmap_name: str="RdBu_r", plot_arrow: bool=True,
                              mark_cell: bool=True, head_width: int=3) -> None:
        """Plot the probability of a cell to transition to any other cell

        This function is untested
        """
        cmap = plt.cm.get_cmap(name=cmap_name)
        colorandum = np.ones((self.embedding.shape[0], 4))
        colorandum *= 0.3
        colorandum[:, -1] = alpha
        
        plt.scatter(self.embedding[:, 0], self.embedding[:, 1],
                    c=colorandum, s=50, edgecolor="")
        if mark_cell:
            plt.scatter(self.embedding[cell_ix, 0], self.embedding[cell_ix, 1],
                        facecolor="none", s=100, edgecolor="k")
        if plot_arrow:
            plt.arrow(self.embedding[cell_ix, 0], self.embedding[cell_ix, 1],
                      self.delta_embedding[cell_ix, 0], self.delta_embedding[cell_ix, 1],
                      head_width=head_width, length_includes_head=True) 
开发者ID:velocyto-team,项目名称:velocyto.py,代码行数:23,代码来源:analysis.py

示例5: draw_es

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def draw_es(id_to_coords, connections, filename):
    fig = plt.figure()
    plt.axis([-1.1, 1.1, -1.1, 1.1])
    fig.add_subplot(111)

    for c in connections:
        color = 'red'
        if c.weight > 0.0:
            color = 'black'
        plt.arrow(c.x1, c.y1, c.x2-c.x1, c.y2-c.y1, head_width=0.00, head_length=0.0, 
                  fc=color, ec=color, length_includes_head = True)

    for (coord, idx) in id_to_coords.iteritems():
        plt.plot(coord[0], coord[1], marker='o', markersize=8.0, color='grey')

    plt.grid()
    fig.savefig(filename) 
开发者ID:ukuleleplayer,项目名称:pureples,代码行数:19,代码来源:visualize.py

示例6: plot_links

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def plot_links(
    graph, color="b", linestyle="solid", with_id=True, as_arrow=True, linewidth=None
):
    if as_arrow:
        head_width = 0.1
    else:
        head_width = 0.0
    for link, nodes in enumerate(graph.nodes_at_link):
        x, y = graph.x_of_node[nodes[0]], graph.y_of_node[nodes[0]]
        dx, dy = graph.x_of_node[nodes[1]] - x, graph.y_of_node[nodes[1]] - y
        plt.arrow(
            x,
            y,
            dx,
            dy,
            head_width=head_width,
            linewidth=linewidth,
            length_includes_head=True,
            color=color,
            linestyle=linestyle,
        )
        if with_id:
            plt.text(x + dx * 0.5, y + dy * 0.5, link, size=16, color=color) 
开发者ID:landlab,项目名称:landlab,代码行数:25,代码来源:graph.py

示例7: subplot

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def subplot(N, n, i, title=True):
    ax = fig.add_subplot(N, 1, i)
    image = np.array(x[n]).T
    ax.imshow(image, cmap=plt.cm.gray, interpolation="nearest")
    if title:
        if n == 0:
            ax.set_title('Before training', **title_font)
        else:
            num = str(n)
            if len(num) > 3:
                num = num[:-3] + "," + num[-3:]
            if len(num) > 7:
                num = num[:-7] + "," + num[-7:]
            ax.set_title('After training ' + num + " times", **title_font)
    plt.tick_params(axis='both', which='both', bottom='off', top='off',
                    right="off", left="off", labelleft="off",
                    labelbottom='off')
    if i == N:
        xlim = ax.get_xlim()
        ylim = ax.get_ylim()
        plt.arrow(xlim[0], ylim[0] + 1, xlim[1] - xlim[0] - 1.5, 0, width=.1,
                  color="k", clip_on=False, head_width=1., head_length=1.5) 
开发者ID:ibm-research-tokyo,项目名称:dybm,代码行数:24,代码来源:MakeEvolutionFigure.py

示例8: _draw_port

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def _draw_port(ax, port, arrow_scale, color):
    # x,y = port.midpoint
    nv = port.normal
    n = (nv[1]-nv[0])
    dx,dy = n*port.width/8*arrow_scale
    dx += n[1]*port.width/8*arrow_scale
    dy += n[0]*port.width/8*arrow_scale
    # dx,dy = np.array(np.cos(port.orientation/180*np.pi), np.sin(port.orientation/180*np.pi))*port.width/10*arrow_scale + \
    #         np.array(np.cos((port.orientation+90)/180*np.pi), np.sin((port.orientation+90)/180*np.pi))*port.width/4*arrow_scale
    # print(port.midpoint)
    # print(port.width)
    # print(nv)
    xbound, ybound = np.column_stack(port.endpoints)
    #plt.plot(x, y, 'rp', markersize = 12) # Draw port midpoint
    arrow_points = np.array([[0,0],[10,0],[6,4],[6,2],[0,2]])/(40)*port.width*arrow_scale
    arrow_points += port.midpoint
    arrow_points = _rotate_points(arrow_points, angle = port.orientation, center = port.midpoint)
    xmin,ymin = np.min(np.vstack([arrow_points,port.endpoints]), axis = 0)
    xmax,ymax = np.max(np.vstack([arrow_points,port.endpoints]), axis = 0)
    ax.plot(xbound, ybound, alpha = 0.5, linewidth = 3, color = color) # Draw port edge
    ax.plot(arrow_points[:,0], arrow_points[:,1], alpha = 0.5, linewidth = 1, color = color) # Draw port edge
    # plt.arrow(x, y, dx, dy,length_includes_head=True, width = 0.1*arrow_scale,
    #           head_width=0.3*arrow_scale, alpha = 0.5, **kwargs)
    ax.text(port.midpoint[0]+dx, port.midpoint[1]+dy, port.name,
        horizontalalignment = 'center', verticalalignment = 'center', fontsize = 14)
    bbox = [xmin,ymin,xmax,ymax]
    return bbox 
开发者ID:amccaugh,项目名称:phidl,代码行数:29,代码来源:quickplotter.py

示例9: clink_handler

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def clink_handler(sxy, exy, style, offsets, roundness, head_length):
    '''a C style link between two edges.'''
    nturn = len(offsets)
    offsets = np.asarray(offsets)
    unit_t = (exy - sxy)/norm(exy - sxy)
    unit_l = rotate(unit_t, np.pi/2.)
    vl, vr = [sxy], [exy]

    # get arrow locations and directions
    # - first, get head and tail vector.
    arrows = []
    unit_head_vec = (-unit_t if nturn%2==0 else unit_l)*(np.sign(offsets[0]) if len(offsets)!=0 else -1)
    sign_eo = -1 if nturn%2 == 0 else 1
    unit_tail_vec = unit_head_vec * sign_eo
    head_vec = unit_head_vec * head_length
    tail_vec = unit_tail_vec * head_length
    if style[0] in ['<', '>']:
        sign = (1 if style[0]=='>' else -1)
        arrows.append((sxy+head_vec*0.6, unit_head_vec * sign))
        style = style[1:]
        vl[0] = vl[0] + head_vec
    if style[-1] in ['<', '>']:
        sign = (-1 if style[-1]=='>' else 1)
        arrows.append((exy+tail_vec*0.6, unit_tail_vec * sign))
        style = style[:-1]
        vr[0] = vr[0] + tail_vec

    # get path
    ls = style
    if len(ls) !=1:
        raise ValueError('style must contain exactly 1 line style code.')
    for i, dxy in enumerate(offsets):
        sxy = sxy + (-unit_t if i%2 == nturn%2 else unit_l)*dxy
        exy = exy + (unit_t if i%2 == nturn%2 else unit_l)*dxy
        vl.append(sxy)
        vr.append(exy)
    return arrows, [(ls, rounded_path(vl+vr[::-1], roundness))], (vl[-1], vr[-1]) 
开发者ID:GiggleLiu,项目名称:viznet,代码行数:39,代码来源:brush.py

示例10: basicline_handler

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def basicline_handler(sxy, exy, style, head_length):
    '''draw a line between start and end.'''
    # the distance and unit distance
    d = np.asarray(exy) - sxy
    unit_d = d / norm(d)

    # get arrow locations.
    arrows = []
    segs = []
    for s in style:
        if s in ['>', '<']:
            sign = 1 if s == '>' else -1
            arrows.append([len(segs), sign*unit_d])
        else:
            segs.append(s)
    head_vec = unit_d * head_length
    vec_d = d - head_vec * 1.2
    num_segs = len(segs)
    for al in arrows:
        al[0] = al[0] * vec_d / max(num_segs, 1) + sxy + 0.6 * head_vec

    # get the line locations.
    uni = d / num_segs
    lines = []
    end = start = sxy
    seg_pre = ''
    for seg in segs:
        if seg != seg_pre and seg_pre != '':
            lines.append([seg_pre, [start, end]])
            start = end
        seg_pre = seg
        end = end + uni
    lines.append([seg, [start, end]])

    # fix end of line
    if style[-1] in ['<', '>']:
        lines[-1][1][1] -= head_vec
    if style[0] in ['<', '>']:
        lines[0][1][0] += head_vec
    return arrows, lines 
开发者ID:GiggleLiu,项目名称:viznet,代码行数:42,代码来源:brush.py

示例11: _arrow

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def _arrow(ax, mxy, direction, head_width, head_length, lw, zorder, color):
    '''draw an arrow.'''
    head_vec = direction * head_length
    mxy = mxy - head_vec * 0.6
    dx, dy = direction
    obj = plt.arrow(*mxy, 1e-8 * dx, 1e-8 * dy,
              head_length=head_length, width=0,
              head_width=head_width, fc=color,
              length_includes_head=False, lw=lw, edgecolor=color, zorder=zorder)
    return obj 
开发者ID:GiggleLiu,项目名称:viznet,代码行数:12,代码来源:brush.py

示例12: draw

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def draw(x, y):
        # set up range of the plot
        limit = max(x, y) + 1

        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.set_aspect('equal')

        # lines corresponding to x- and y-coordinates
        plt.plot([x, x], [0, y], '-', c='blue', linewidth=3)
        plt.plot([0, x], [y, y], '-', c='blue', linewidth=3)

        plt.scatter(x, y, s=100, marker='o', c='red')  # actual point

        ax.set_xlim((-limit, limit))
        ax.set_ylim((-limit, limit))

        # axis arrows
        left, right = ax.get_xlim()
        bottom, top = ax.get_ylim()
        plt.arrow(left, 0, right - left, 0, length_includes_head=True,
                  head_width=0.15)
        plt.arrow(0, bottom, 0, top - bottom, length_includes_head=True,
                  head_width=0.15)

        plt.grid()
        plt.show() 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:29,代码来源:point_v3.py

示例13: show_assignments

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def show_assignments(a, b, P, title=""):
    norm_P = P / P.max()
    for i in range(a.shape[0]):
        for j in range(b.shape[0]):
            plt.arrow(a[i, 0], a[i, 1], b[j, 0] - a[i, 0], b[j, 1] - a[i, 1],
                      alpha=norm_P[i, j].item() / 2)
    plt.scatter(a[:, 0], a[:, 1], label="target")
    plt.scatter(b[:, 0], b[:, 1], label="prediction")
    plt.axis('off')
    plt.legend(prop={'size': 20})
    plt.title(f'StreetMover: {title[:6]}', fontsize=25)
    plt.tight_layout()
    # plt.show()
    plt.savefig(f"./sinkhorn/wass{title}.png")
    plt.clf() 
开发者ID:davide-belli,项目名称:generative-graph-transformer,代码行数:17,代码来源:streetmover_distance.py

示例14: visualize_values

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def visualize_values(mdp, values, policy, filename, title=None):
    states = mdp.states
    # print states
    plt.clf()
    m = max(states, key=lambda x: x[0])[0] + 1
    n = max(states, key=lambda x: x[1])[1] + 1
    data = np.zeros((m,n))
    for i in range(m):
        for j in range(n):
            state = (i,j)
            if type(values) == dict:
                data[i][j] = values[state]
            else:
                # print values[i][j]
                data[i][j] = values[i][j]
            action = policy[state]
            ## if using all_reachable actions, pick the best one
            if type(action) == tuple:
                action = action[0]
            if action != None:
                x, y, w, h = arrow(i, j, action)
                plt.arrow(x,y,w,h,head_length=0.4,head_width=0.4,fc='k',ec='k')
    heatmap = plt.pcolor(data, cmap=plt.get_cmap('jet'))
    plt.colorbar()
    plt.gca().invert_yaxis()

    if title:
        plt.title(title)
    plt.savefig(filename + '.png')
    # print data 
开发者ID:JannerM,项目名称:spatial-reasoning,代码行数:32,代码来源:visualization.py

示例15: arrow

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import arrow [as 别名]
def arrow(i, j, action):
    ## up, down, left, right
    ## x, y, w, h
    arrows = {0: (.5,.95,0,-.4), 1: (.5,.05,0,.4), 2: (.95,.5,-.4,0), 3: (.05,.5,.4,0)}
    arrow = arrows[action]
    return j+arrow[0], i+arrow[1], arrow[2], arrow[3] 
开发者ID:JannerM,项目名称:spatial-reasoning,代码行数:8,代码来源:visualization.py


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