Ejemplo n.º 1
0
    def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False, \
        head_width=None, head_length=None, shape='full', overhang=0, \
        head_starts_at_zero=False,**kwargs):
        """Returns a new Arrow.

        length_includes_head: True if head is counted in calculating the length.
        
        shape: ['full', 'left', 'right']
        
        overhang: distance that the arrow is swept back (0 overhang means
        triangular shape).

        head_starts_at_zero: if True, the head starts being drawn at coordinate
        0 instead of ending at coordinate 0.
        """
        if head_width is None:
            head_width = 3 * width
        if head_length is None:
            head_length = 1.5 * head_width

        distance = sqrt(dx**2 + dy**2)
        if length_includes_head:
            length=distance
        else:
            length=distance+head_length
        if not length:
            verts = [] #display nothing if empty
        else:
            #start by drawing horizontal arrow, point at (0,0)
            hw, hl, hs, lw = head_width, head_length, overhang, width
            left_half_arrow = array([
                [0.0,0.0],                  #tip
                [-hl, -hw/2.0],             #leftmost
                [-hl*(1-hs), -lw/2.0], #meets stem
                [-length, -lw/2.0],          #bottom left
                [-length, 0],
            ])
            #if we're not including the head, shift up by head length
            if not length_includes_head:
                left_half_arrow += [head_length, 0]
            #if the head starts at 0, shift up by another head length
            if head_starts_at_zero:
                left_half_arrow += [head_length/2.0, 0]
            #figure out the shape, and complete accordingly
            if shape == 'left':
                coords = left_half_arrow
            else:
                right_half_arrow = left_half_arrow*[1,-1]
                if shape == 'right':
                    coords = right_half_arrow
                elif shape == 'full':
                    coords=concatenate([left_half_arrow,right_half_arrow[::-1]])
                else:
                    raise ValueError, "Got unknown shape: %s" % shape
            cx = float(dx)/distance
            sx = float(dy)/distance
            M = array([[cx, sx],[-sx,cx]])
            verts = dot(coords, M) + (x+dx, y+dy)
        
        Polygon.__init__(self, map(tuple, verts), **kwargs)
Ejemplo n.º 2
0
    def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False, \
        head_width=None, head_length=None, shape='full', overhang=0, \
        head_starts_at_zero=False,**kwargs):
        """Returns a new Arrow.

        length_includes_head: True if head is counted in calculating the length.
        
        shape: ['full', 'left', 'right']
        
        overhang: distance that the arrow is swept back (0 overhang means
        triangular shape).

        head_starts_at_zero: if True, the head starts being drawn at coordinate
        0 instead of ending at coordinate 0.
        """
        if head_width is None:
            head_width = 3 * width
        if head_length is None:
            head_length = 1.5 * head_width

        distance = sqrt(dx**2 + dy**2)
        if length_includes_head:
            length=distance
        else:
            length=distance+head_length
        if not length:
            verts = [] #display nothing if empty
        else:
            #start by drawing horizontal arrow, point at (0,0)
            hw, hl, hs, lw = head_width, head_length, overhang, width
            left_half_arrow = array([
                [0.0,0.0],                  #tip
                [-hl, -hw/2.0],             #leftmost
                [-hl*(1-hs), -lw/2.0], #meets stem
                [-length, -lw/2.0],          #bottom left
                [-length, 0],
            ])
            #if we're not including the head, shift up by head length
            if not length_includes_head:
                left_half_arrow += [head_length, 0]
            #if the head starts at 0, shift up by another head length
            if head_starts_at_zero:
                left_half_arrow += [head_length/2.0, 0]
            #figure out the shape, and complete accordingly
            if shape == 'left':
                coords = left_half_arrow
            else:
                right_half_arrow = left_half_arrow*[1,-1]
                if shape == 'right':
                    coords = right_half_arrow
                elif shape == 'full':
                    coords=concatenate([left_half_arrow,right_half_arrow[::-1]])
                else:
                    raise ValueError, "Got unknown shape: %s" % shape
            cx = float(dx)/distance
            sx = float(dy)/distance
            M = array([[cx, sx],[-sx,cx]])
            verts = dot(coords, M) + (x+dx, y+dy)
        
        Polygon.__init__(self, map(tuple, verts), **kwargs)
Ejemplo n.º 3
0
 def __init__(self, xyz, **kargs):
     self._gl_3dpath = kargs.pop('gl_3dpath', None)
     self._gl_lighting = kargs.pop('gl_lighting', True)
     xy = xyz[:,0:2]
     Polygon.__init__(self, xy, **kargs)
     self.do_stencil_test = True
     self.set_3d_properties(zs = xyz[:,2])
Ejemplo n.º 4
0
 def __init__(self, center, radius, **kwargs):
     self.point_array = None
     self.kwargs = kwargs
     self.center = None
     self.radius = None
     self.base_mask = None
     Polygon.__init__(self, np.array([[0, 0], [1, 1]]), **kwargs)
     self.center = np.array(center).ravel()  # make sure it's a row vector
     self.set_radius(radius)
Ejemplo n.º 5
0
    def __init__(self, x, y, dx, dy, invert=False, **kwargs):
        """Returns a new letter."""
        if invert:
            self.verts = fabs(self.verts - 100)

        verts = (100. - array(self.verts)) / 100.
        verts *= [dx, dy]
        verts += [x, y]
        Polygon.__init__(self,
                         list(map(tuple, verts)),
                         facecolor=self.color,
                         edgecolor=self.color,
                         **kwargs)
Ejemplo n.º 6
0
    def __init__(self, fig, pointList, polygonLine, colTuple):
        self.fig = fig
        self.pointList = pointList  # List of drag points
        self.polygonLine = polygonLine
        self.pts = []  # [[x1,y1],[x2,y2],...[xn,yn]]
        self.polyCreated = False

        # Initialise first points
        self.ptsFromDragPointList()
        for pt in self.pointList:
            # Set Point connected polygon
            pt.masterPoly = self

        # Initialise polygon
        Polygon.__init__(self, self.pts, alpha=0.3, fc=colTuple, closed=True)

        # Add poly to axes
        self.fig.axes[0].add_patch(self)
Ejemplo n.º 7
0
    def __init__(self, filename, **kwargs):
        """
        Create a new coastline polygon.

        Parameters
        ----------
        color : color, optional, default 'gray'
            Line color of the coastline.
        land : color, optional, default 'seashell'
            Fill color of the land polygons.

        Other parameters
        ----------------
        kwargs : polygon properties
            Other parameters passed on to :class:`~matplotlib.patches.Polygon`,
            e.g. zorder=N to control drawing the land polygons above/below
            other data.
        """
        color = kwargs.pop('color', 'gray')
        land = kwargs.pop('land', 'seashell')
        self.data = []
        self.extents = None

        if not color:
            color = 'none'
        if not land:
            land = 'none'

        xy = [[None, None], [None, None]]
        Polygon.__init__(self, xy, edgecolor=color, facecolor=land, **kwargs)

        datapath = os.path.join(os.path.dirname(__file__), 'data')
        coastfile = _find(filename, datapath)
        if coastfile:
            file = shapefile.Reader(coastfile)
            for shape in file.shapes():
                for points in _split(shape.points, shape.parts):
                    self.data += [Path(points)]
        else:
            raise Warning('coastline "%s" not found in directory "%s"' % (filename, datapath))
Ejemplo n.º 8
0
 def __init__(self, x, y, dx, dy, tail_width=None, length_includes_head=True,
     head_width=None, head_length=None, shape='full', overhang=None,
     head_starts_at_zero=False, **kwargs):
     """
       *head_length*: Length of arrow head
         float or None. Default: 0.2 * total length
       *head_width*: Specified as fraction of head_length!
         float or None. Default: 0.5
        *overhang*: Specified as fraction of head legnth!
         Positive number means swept back, negative swept forward.
         float or None. Default: 0.2
       *tail_width*: width of full arrow tail
         float or None. Default: Length/50
       *shape*: ['full', 'left', 'right'] (default: 'full')
         draw the left-half, right-half, or full arrow
       *head_starts_at_zero*: [True | False] (default: False)
         if True, the head starts being drawn at coordinate 0
         instead of ending at coordinate 0.
       *length_includes_head*: [True | False] (default: False)
         True if head is to be counted in calculating the length.            
     Other valid kwargs (inherited from :class:`Patch`) are:
     %(Patch)s
     """
     distance = n.sqrt(dx ** 2 + dy ** 2)
     length = distance
     if head_length is None:
         head_length = .2 * length
     if not length_includes_head:
          length = distance + head_length
     if head_width is None:
         head_width = 0.6 
     if overhang is None:
         overhang = 0.3
     if tail_width is None:
         tail_width = .0035
     if not length:
         verts = []  # display nothing if empty
     else:
         hw, hl, oh, lw = head_width, head_length, overhang, tail_width
         left_half_arrow = n.array([
            [0.0, 0.0],                  # rear_center
             [0, -lw / 2.0],             # rear corner
             [length-hl, -lw / 2.0],     # feather-stem intersection
             [length-hl*(1+oh), -hw*hl / 2.0],          # sweep back
             [length, 0],                   # tip
             ])
         
         left_half_arrow += [-length, 0] # Keeps positioning consistent with MPL's arrow so I can use
                                         # their transformation below
         
         #p.figure(4)
         #p.plot(left_half_arrow[:,0],left_half_arrow[:,1],'-o')
         #for i in range(len(left_half_arrow)):
         #    p.text(left_half_arrow[i,0],left_half_arrow[i,1],'{}\n'.format(i),va='bottom',color='k',size=14)
             
         #if we're not including the head, shift up by head length
         if not length_includes_head:
             left_half_arrow += [head_length, 0]
         #if the head starts at 0, shift up by another head length
         if head_starts_at_zero:
             left_half_arrow += [head_length / 2.0, 0]
         #figure out the shape, and complete accordingly
         left_half_arrow = left_half_arrow[1:]
         if shape == 'left':
             coords = left_half_arrow
         else:
             right_half_arrow = n.flipud(left_half_arrow)[1:]*[1,-1]
             if shape == 'right':
                 coords = right_half_arrow
             elif shape == 'full':
                 # The half-arrows contain the midpoint of the stem,
                 # which we can omit from the full arrow. Including it
                 # twice caused a problem with xpdf.
                 coords = n.concatenate([left_half_arrow[:],
                                          right_half_arrow[:]])
                 coords = n.vstack( (coords,coords[0]) )[0:-1]
                 #p.figure(5)
                 #p.plot(coords[:,0],coords[:,1],'-o')
                 #for i in range(len(coords)):
                 #    #p.text(0,0,'what')
                 #    p.text(coords[i,0],coords[i,1],'{}\n'.format(i),va='bottom',color='k',size=14)
             else:
                 raise ValueError("Got unknown shape: %s" % shape)
         cx = float(dx) / distance
         sx = float(dy) / distance
         M = n.array([[cx, sx], [-sx, cx]])
         #verts = n.dot(coords, M)
         #p.figure(2)
         #p.plot(verts[:,0],verts[:,1],lw=1)
         #for i in verts:
         #    p.text(i[0],i[1],'({:.3f},{:.3f})'.format(i[0],i[1]),size=6)
         #verts += [x,y]
         #p.figure(6)
         #p.plot(verts[:,0],verts[:,1])
         #verts += [dx,dy]
         #p.figure(7)
         #p.plot(verts[:,0],verts[:,1])
         verts = n.dot(coords, M) + [x+dx, y+dy]
     Polygon.__init__(self, list(map(tuple, verts)), closed=True, **kwargs)    
Ejemplo n.º 9
0
    def __init__(self, start_ls, end_ls, y=0, width=0.001, x_offset=0, is_arrow=True, length_includes_head=True, \
     head_width=None, head_length=None, shape='full', overhang=0, \
     head_starts_at_zero=False,**kwargs):
        """2008-02-02 an artist for gene. block-like. based on matplotlib.patches.FancyArrow
		
		Returns a new Arrow.
		
		x_offset: is the value of how far start_ls and end_ls should all be pushed
		
		is_arrow: True if it's an arrow. False if it's just a rectangle
		
		length_includes_head: True if head is counted in calculating the length.

		shape: ['full', 'left', 'right']

		overhang: ratio of the head_length that the arrow is swept back (0 overhang means
		triangular shape).

		head_starts_at_zero: if True, the head starts being drawn at coordinate
		0 instead of ending at coordinate 0.

		Valid kwargs are:
		%(Patch)s

		"""
        if head_width is None:
            head_width = 2 * width
        if head_length is None:
            head_length = 1 / (2.0 * abs(end_ls[0] - start_ls[0]))

        distance = abs(end_ls[-1] - start_ls[0])
        if length_includes_head:
            length = distance
        else:
            length = distance + head_length

        no_of_blocks = len(start_ls)
        if not distance:
            verts = []  #display nothing if empty
        else:
            """
			start by drawing horizontal arrow, point (tip of the arrow) at (0,0). the whole arrow sticks on the x-axis (<=0 part)
			Notice: the XY -coordination is not the usual math coordination system. it's canvas coordination. (0,0) is top left. horizontal is y-axis. vertical is x-axis.
			start from the last block, reversely to the 1st block
			"""
            inc_block_length = abs(end_ls[-1] - start_ls[-1])
            hw, hl = head_width, head_length
            if is_arrow:
                left_half_arrow_ls = [
                    [0.0, 0.0],  #tip
                    [-hl, -hw / 2.0],  #leftmost
                    [-hl * (1 - overhang), -width / 2.0],  #meets stem
                    [-inc_block_length, -width / 2.0]  #bottom left
                ]
            else:  #this is just a rectangle
                left_half_arrow_ls = [
                    [0.0, 0.0],  #tip
                    [0.0, -width / 2.0],  #left to the tip
                    [-inc_block_length, -width / 2.0]  #bottom left
                ]
            if no_of_blocks == 1:  #only one block, seal it
                left_half_arrow_ls.append([-inc_block_length, 0])
            elif no_of_blocks > 1:  #more than one block
                left_half_arrow_ls.append([-inc_block_length,
                                           -width / 6.0])  #leave if open
                for i in range(1, no_of_blocks):
                    block_index = -i - 1  #backwards
                    gap = abs(start_ls[block_index + 1] - end_ls[block_index])
                    inc_block_start = inc_block_length + gap
                    this_block_length = abs(end_ls[block_index] -
                                            start_ls[block_index])
                    inc_block_length = inc_block_length + gap + this_block_length
                    if i != no_of_blocks - 1:  #don't seal it
                        left_half_arrow_ls.append(
                            [-inc_block_start, -width / 6.0])
                        left_half_arrow_ls.append(
                            [-inc_block_start, -width / 2.0])
                        left_half_arrow_ls.append(
                            [-inc_block_length, -width / 2.0])
                        left_half_arrow_ls.append(
                            [-inc_block_length, -width / 6.0])
                    else:  #seal it
                        left_half_arrow_ls.append(
                            [-inc_block_start, -width / 6.0])
                        left_half_arrow_ls.append(
                            [-inc_block_start, -width / 2.0])
                        left_half_arrow_ls.append(
                            [-inc_block_length, -width / 2.0])
                        left_half_arrow_ls.append([-inc_block_length, 0])
            left_half_arrow = array(left_half_arrow_ls)
            #if we're not including the head, shift up by head length
            if not length_includes_head:
                left_half_arrow += [head_length, 0]
            #if the head starts at 0, shift up by another head length
            if head_starts_at_zero:
                left_half_arrow += [head_length / 2.0, 0]
            #figure out the shape, and complete accordingly
            if shape == 'left':
                coords = left_half_arrow
            else:
                right_half_arrow = left_half_arrow * [1, -1]
                if shape == 'right':
                    coords = right_half_arrow
                elif shape == 'full':
                    coords = concatenate(
                        [left_half_arrow, right_half_arrow[::-1]])
                else:
                    raise ValueError, "Got unknown shape: %s" % shape
            dx = end_ls[-1] - start_ls[0]
            x = start_ls[0] + x_offset
            dy = 0
            cx = float(dx) / distance
            sx = float(dy) / distance
            M = array([[cx, sx], [-sx, cx]])
            #verts = matrixmultiply(coords, M) + (x+dx, y+dy)
            verts = coords * M + (
                x + dx, y + dy
            )  #2012.7.9 replace matrixmultiply with "*" as matrixmultiply is not available from numpy
        Polygon.__init__(self, map(tuple, verts), **kwargs)
Ejemplo n.º 10
0
	def __init__(self, start_ls, end_ls, y=0, width=0.001, x_offset=0, is_arrow=True, length_includes_head=True, \
		head_width=None, head_length=None, shape='full', overhang=0, \
		head_starts_at_zero=False,**kwargs):
		"""2008-02-02 an artist for gene. block-like. based on matplotlib.patches.FancyArrow
		
		Returns a new Arrow.
		
		x_offset: is the value of how far start_ls and end_ls should all be pushed
		
		is_arrow: True if it's an arrow. False if it's just a rectangle
		
		length_includes_head: True if head is counted in calculating the length.

		shape: ['full', 'left', 'right']

		overhang: ratio of the head_length that the arrow is swept back (0 overhang means
		triangular shape).

		head_starts_at_zero: if True, the head starts being drawn at coordinate
		0 instead of ending at coordinate 0.

		Valid kwargs are:
		%(Patch)s

		"""
		if head_width is None:
			head_width = 2 * width
		if head_length is None:
			head_length = 1/(2.0 * abs(end_ls[0]-start_ls[0]))

		distance = abs(end_ls[-1]-start_ls[0])
		if length_includes_head:
			length=distance
		else:
			length=distance+head_length
		
		no_of_blocks = len(start_ls)
		if not distance:
			verts = [] #display nothing if empty
		else:
			"""
			start by drawing horizontal arrow, point (tip of the arrow) at (0,0). the whole arrow sticks on the x-axis (<=0 part)
			Notice: the XY -coordination is not the usual math coordination system. it's canvas coordination. (0,0) is top left. horizontal is y-axis. vertical is x-axis.
			start from the last block, reversely to the 1st block
			"""
			inc_block_length = abs(end_ls[-1]-start_ls[-1])
			hw, hl = head_width, head_length
			if is_arrow:
				left_half_arrow_ls = [
    				[0.0,0.0],				  #tip
    				[-hl, -hw/2.0],			 #leftmost
    				[-hl*(1-overhang), -width/2.0], #meets stem
    				[-inc_block_length, -width/2.0]		 #bottom left
    			]
			else:	#this is just a rectangle
				left_half_arrow_ls = [
    				[0.0,0.0],				  #tip
    				[0.0, -width/2.0],		#left to the tip
    				[-inc_block_length, -width/2.0]		 #bottom left
    			]
			if no_of_blocks==1:	#only one block, seal it
				left_half_arrow_ls.append([-inc_block_length, 0])
			elif no_of_blocks>1:	#more than one block
				left_half_arrow_ls.append([-inc_block_length, -width/6.0])   #leave if open
				for i in range(1, no_of_blocks):
					block_index = -i-1	#backwards
					gap = abs(start_ls[block_index+1]-end_ls[block_index])
					inc_block_start = inc_block_length + gap
					this_block_length = abs(end_ls[block_index]-start_ls[block_index])
					inc_block_length = inc_block_length + gap + this_block_length
					if i!=no_of_blocks-1:	#don't seal it
						left_half_arrow_ls.append([-inc_block_start, -width/6.0])
						left_half_arrow_ls.append([-inc_block_start, -width/2.0])
						left_half_arrow_ls.append([-inc_block_length, -width/2.0])
						left_half_arrow_ls.append([-inc_block_length, -width/6.0])
					else:	#seal it
						left_half_arrow_ls.append([-inc_block_start, -width/6.0])
						left_half_arrow_ls.append([-inc_block_start, -width/2.0])
						left_half_arrow_ls.append([-inc_block_length, -width/2.0])
						left_half_arrow_ls.append([-inc_block_length, 0])
			left_half_arrow = array(left_half_arrow_ls)
			#if we're not including the head, shift up by head length
			if not length_includes_head:
				left_half_arrow += [head_length, 0]
			#if the head starts at 0, shift up by another head length
			if head_starts_at_zero:
				left_half_arrow += [head_length/2.0, 0]
			#figure out the shape, and complete accordingly
			if shape == 'left':
				coords = left_half_arrow
			else:
				right_half_arrow = left_half_arrow*[1,-1]
				if shape == 'right':
					coords = right_half_arrow
				elif shape == 'full':
					coords=concatenate([left_half_arrow,right_half_arrow[::-1]])
				else:
					raise ValueError, "Got unknown shape: %s" % shape
			dx = end_ls[-1]-start_ls[0]
			x = start_ls[0] + x_offset
			dy = 0
			cx = float(dx)/distance
			sx = float(dy)/distance
			M = array([[cx, sx],[-sx,cx]])
			verts = matrixmultiply(coords, M) + (x+dx, y+dy)

		Polygon.__init__(self, map(tuple, verts), **kwargs)
Ejemplo n.º 11
0
    def __init__(self,
                 x,
                 y,
                 dx,
                 dy,
                 width=0.001,
                 length_includes_head=False,
                 head_width=None,
                 head_length=None,
                 shape='full',
                 overhang=0,
                 head_starts_at_zero=False,
                 **kwargs):
        """
        Constructor arguments
          *width*: float (default: 0.001)
            width of full arrow tail

          *length_includes_head*: [True | False] (default: False)
            True if head is to be counted in calculating the length.

          *head_width*: float or None (default: 3*width)
            total width of the full arrow head

          *head_length*: float or None (default: 1.5 * head_width)
            length of arrow head

          *shape*: ['full', 'left', 'right'] (default: 'full')
            draw the left-half, right-half, or full arrow

          *overhang*: float (default: 0)
            fraction that the arrow is swept back (0 overhang means
            triangular shape). Can be negative or greater than one.

          *head_starts_at_zero*: [True | False] (default: False)
            if True, the head starts being drawn at coordinate 0
            instead of ending at coordinate 0.

        Other valid kwargs (inherited from :class:`Patch`) are:
        %(Patch)s

        """
        if head_width is None:
            head_width = 3 * width
        if head_length is None:
            head_length = 1.5 * head_width

        distance = np.hypot(dx, dy)

        if length_includes_head:
            length = distance
        else:
            length = distance + head_length
        if not length:
            verts = []  # display nothing if empty
        else:
            # start by drawing horizontal arrow, point at (0,0)
            hw, hl, hs, lw = head_width, head_length, overhang, width
            left_half_arrow = np.array([
                [0.0, 0.0],  # tip
                [-hl, -hw / 2.0],  # leftmost
                [-hl * (1 - hs), -lw / 2.0],  # meets stem
                [-length, -lw / 2.0],  # bottom left
                [-length, 0],
            ])
            # if we're not including the head, shift up by head length
            if not length_includes_head:
                left_half_arrow += [head_length, 0]
            # if the head starts at 0, shift up by another head length
            if head_starts_at_zero:
                left_half_arrow += [head_length / 2.0, 0]
            # figure out the shape, and complete accordingly
            if shape == 'left':
                coords = left_half_arrow
            else:
                right_half_arrow = left_half_arrow * [1, -1]
                if shape == 'right':
                    coords = right_half_arrow
                elif shape == 'full':
                    # The half-arrows contain the midpoint of the stem,
                    # which we can omit from the full arrow. Including it
                    # twice caused a problem with xpdf.
                    coords = np.concatenate(
                        [left_half_arrow[:-1], right_half_arrow[-1::-1]])
                else:
                    raise ValueError("Got unknown shape: %s" % shape)
            if distance != 0:
                cx = float(dx) / distance
                sx = float(dy) / distance
            else:
                #Account for division by zero
                cx, sx = 0, 1
            M = np.array([[cx, sx], [-sx, cx]])
            verts = np.dot(coords, M) + (x + dx, y + dy)

        Polygon.__init__(self, list(map(tuple, verts)), closed=True, **kwargs)