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

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

项目:pureples    作者:ukuleleplayer    | 项目源码 | 文件源码
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)
项目:electrostatics    作者:tomduck    | 项目源码 | 文件源码
def plot(self, linewidth=None, startarrows=True, endarrows=True):
        """Plots the field line and arrows."""

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

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

        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)
项目:autoxd    作者:nessessary    | 项目源码 | 文件源码
def AddBuyOrSellArrow(self, x, y, buy=True):
        """"""
        if buy:
            plt.arrow(x, y, 1, 2)
        else:
            plt.arrow(x, y, 1, -2)



    #
    #?????x?y? ????
    #----------------------------------------------------------------------
项目:IRL    作者:ashwindharne    | 项目源码 | 文件源码
def drawArrow(A, B):
    plt.arrow(A[0], A[1], B[0]-A[0], B[1]-A[1], head_width=0.125, head_length=0.125)
项目:IRL    作者:ashwindharne    | 项目源码 | 文件源码
def drawArrow(A, B):
    plt.arrow(A[0], A[1], B[0]-A[0], B[1]-A[1], head_width=0.125, head_length=0.125)
项目:particle_filter    作者:rcorona    | 项目源码 | 文件源码
def plot_particles(rosbag_name):
    bag = rosbag.Bag(rosbag_name, 'r')
    counter = 0

    for topic, msg, t in bag.read_messages():
        if topic == '/particle_filter':
            if counter <= 30: 
                x_points = []
                y_points = []

                for i in range(len(msg.particles)):
                    x_points.append(msg.particles[i].pose.x)
                    y_points.append(msg.particles[i].pose.y)

                plt.plot(x_points, y_points, colors[counter % 5])

            counter += 1

    plt.gca().set_xlim([0, 50])
    plt.gca().set_ylim([-35, 30])

    plt.arrow(0, 0, 50, 0)

    plt.ylabel("y (m)")
    plt.xlabel("x (m)")

    #Title
    if len(sys.argv) > 2:
        title = sys.argv[2]
    else:
        title = ""

    plt.title(title)

    plt.show()
项目:spatial-reasoning    作者:JannerM    | 项目源码 | 文件源码
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
项目:spatial-reasoning    作者:JannerM    | 项目源码 | 文件源码
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]
项目:HamiltonianPy    作者:waltergu    | 项目源码 | 文件源码
def view(self,bondselect=None,termselect=None,pidon=True,bonddr='+',show=True,suspend=False,close=True):
        '''
        View the index packs of the terms on the bonds.

        Parameters
        ----------
        bondselect : callable, optional
            The select function of the bonds.
        termselect : callable, optional
            The select function of the terms.
        pidon : logical, optional
            True for showing the pids of the points of the bonds.
        bonddr : '+'/'-', optional
            The direction of the bonds.
        show : logical, optional
            True for showing the view and False for not.
        suspend : logical, optional
            True for suspending the view and False for not.
        close : logical, optional
            True for closing the view and False for not.
        '''
        plt.axis('off')
        plt.axis('equal')
        xmax,xmin,ymax,ymin=0,0,0,0
        points,font=set(),FontProperties(style='italic',weight='bold',size='large')
        for bond in self.bonds:
            assert len(bond.rcoord)==2
            for i,point in enumerate([bond.spoint,bond.epoint]):
                pid=point.pid
                xmax,xmin=max(xmax,point.rcoord[0]),min(xmin,point.rcoord[0])
                ymax,ymin=max(ymax,point.rcoord[1]),min(ymin,point.rcoord[1])
                if pid not in points:
                    x,y=point.rcoord if i==0 else point.rcoord-bond.icoord
                    plt.scatter(x,y,zorder=2,alpha=0.5)
                    if pidon: plt.text(x,y,'%s%s'%('' if pid.scope is None else '%s*'%pid.scope,pid.site),color='blue',horizontalalignment='center',fontproperties=font)
                    points.add(point.pid)
            if bondselect is None or bondselect(bond):
                assert bonddr in ('+','-')
                (x,y),(dx,dy)=(bond.spoint.rcoord,bond.rcoord) if bonddr=='+' else (bond.epoint.rcoord,bond.reversed.rcoord)
                if nl.norm(bond.rcoord)>RZERO: plt.arrow(x,y,dx,dy,ls='--' if nl.norm(bond.icoord)>RZERO else '-',lw=2,color='red',length_includes_head=True,alpha=0.5)
                packs=[term.strrep(bond,self.config) for term in it.chain(self.terms['const'],self.terms['alter']) if termselect is None or termselect(term)]
                if len(packs)>0:
                    plt.text(x+dx/2,y+dy/2,'\n'.join(sorted(packs,key=len)),color='green',horizontalalignment='center',verticalalignment='center',fontproperties=font)
        plt.xlim([xmin-(xmax-xmin)*0.30,xmax+(xmax-xmin)*0.30])
        plt.ylim([ymin-(ymax-ymin)*0.30,ymax+(ymax-ymin)*0.30])
        if show and suspend: plt.show()
        if show and not suspend: plt.pause(1)
        if close: plt.close()
项目:particle_filter    作者:rcorona    | 项目源码 | 文件源码
def plot_gps(self, topic_data):
        print 'Plotting gps...'

        x_points = []
        y_points = []

        #Processes each message.  
        for msg_time in topic_data['/navsat/fix']:
            msg = msg_time[0]

            x, y = self.gps_to_meters(msg.latitude, msg.longitude)

            #Appends gps reading only if it differs from last one. 
            if len(x_points) == 0 or not (x == x_points[len(x_points) - 1] and y == y_points[len(y_points) - 1]):
                x_points.append(x)
                y_points.append(y)

        #Gets heading estimates from GPS. 
        theta_points = self.get_heading_from_gps_points(x_points, y_points)

        #Plots heading. 
        plt.plot(range(len(theta_points)), theta_points)
        plt.show()

        #Places map overlay on graph if needed. 
        if not self.map_img_file == None:
            plt.imshow(self.map_img_file, zorder=0, extent=[0.0, self.width, 0.0, self.height])

        #Plots arrows. 
        for i in range(len(x_points)): 
            x = x_points[i]
            y = y_points[i]
            theta = theta_points[i]

            length = 1
            x_len = math.cos(theta)
            y_len = math.sin(theta)

            plt.arrow(x, y, x_len, y_len, fc = 'k', ec = 'k', head_width = 0.1, head_length = 0.1)

        plt.show()

        #Plots points. 
        plt.plot(x_points, y_points, 'ro')
        plt.show()