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


Python Polygon.__init__方法代码示例

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


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

示例1: __init__

# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import __init__ [as 别名]
    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)
开发者ID:miklou,项目名称:pycogent,代码行数:62,代码来源:fancy_arrow.py

示例2: __init__

# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import __init__ [as 别名]
 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])
开发者ID:piScope,项目名称:piScope,代码行数:9,代码来源:art3d_gl.py

示例3: __init__

# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import __init__ [as 别名]
    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))
开发者ID:ej81,项目名称:mercator,代码行数:42,代码来源:coastline.py

示例4: __init__

# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import __init__ [as 别名]
 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)    
开发者ID:saintsfan342000,项目名称:MPL-a-al-SKK,代码行数:101,代码来源:figfun.py


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