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


Python FancyArrowPatch.set_zorder方法代码示例

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


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

示例1: _render_on_subplot

# 需要导入模块: from matplotlib.patches import FancyArrowPatch [as 别名]
# 或者: from matplotlib.patches.FancyArrowPatch import set_zorder [as 别名]
    def _render_on_subplot(self, subplot):
        """
        Render this arrow in a subplot.  This is the key function that
        defines how this arrow graphics primitive is rendered in
        matplotlib's library.

        EXAMPLES::

        This function implicitly ends up rendering this arrow on a matplotlib subplot:
            sage: arrow(path=[[(0,1), (2,-1), (4,5)]])
        """
        options = self.options()
        width = float(options['width'])
        head = options.pop('head')
        if head == 0: style = '<|-'
        elif head == 1: style = '-|>'
        elif head == 2: style = '<|-|>'
        else: raise KeyError('head parameter must be one of 0 (start), 1 (end) or 2 (both).')
        arrowsize = float(options.get('arrowsize',5))
        head_width=arrowsize
        head_length=arrowsize*2.0
        color = to_mpl_color(options['rgbcolor'])
        from matplotlib.patches import FancyArrowPatch
        from matplotlib.path import Path
        bpath = Path(self.vertices, self.codes)
        p = FancyArrowPatch(path=bpath,
                            lw=width, arrowstyle='%s,head_width=%s,head_length=%s'%(style,head_width, head_length), 
                            fc=color, ec=color, linestyle=options['linestyle'])
        p.set_zorder(options['zorder'])
        p.set_label(options['legend_label'])
        subplot.add_patch(p)
        return p
开发者ID:pombredanne,项目名称:sage-1,代码行数:34,代码来源:arrow.py

示例2: _render_on_subplot

# 需要导入模块: from matplotlib.patches import FancyArrowPatch [as 别名]
# 或者: from matplotlib.patches.FancyArrowPatch import set_zorder [as 别名]
    def _render_on_subplot(self, subplot):
        """
        Render this arrow in a subplot.  This is the key function that
        defines how this arrow graphics primitive is rendered in
        matplotlib's library.

        EXAMPLES::

        This function implicitly ends up rendering this arrow on a matplotlib subplot:
            sage: arrow(path=[[(0,1), (2,-1), (4,5)]])
            Graphics object consisting of 1 graphics primitive
        """
        from sage.plot.misc import get_matplotlib_linestyle

        options = self.options()
        width = float(options["width"])
        head = options.pop("head")
        if head == 0:
            style = "<|-"
        elif head == 1:
            style = "-|>"
        elif head == 2:
            style = "<|-|>"
        else:
            raise KeyError("head parameter must be one of 0 (start), 1 (end) or 2 (both).")
        arrowsize = float(options.get("arrowsize", 5))
        head_width = arrowsize
        head_length = arrowsize * 2.0
        color = to_mpl_color(options["rgbcolor"])
        from matplotlib.patches import FancyArrowPatch
        from matplotlib.path import Path

        bpath = Path(self.vertices, self.codes)
        p = FancyArrowPatch(
            path=bpath,
            lw=width,
            arrowstyle="%s,head_width=%s,head_length=%s" % (style, head_width, head_length),
            fc=color,
            ec=color,
        )
        p.set_linestyle(get_matplotlib_linestyle(options["linestyle"], return_type="long"))
        p.set_zorder(options["zorder"])
        p.set_label(options["legend_label"])
        subplot.add_patch(p)
        return p
开发者ID:sharmaeklavya2,项目名称:sage,代码行数:47,代码来源:arrow.py

示例3: _render_on_subplot

# 需要导入模块: from matplotlib.patches import FancyArrowPatch [as 别名]
# 或者: from matplotlib.patches.FancyArrowPatch import set_zorder [as 别名]
    def _render_on_subplot(self, subplot):
        r"""
        Render this arrow in a subplot.  This is the key function that
        defines how this arrow graphics primitive is rendered in
        matplotlib's library.

        EXAMPLES:

        This function implicitly ends up rendering this arrow on
        a matplotlib subplot::

            sage: arrow((0,1), (2,-1))

        TESTS:

        The length of the ends (shrinkA and shrinkB) should not depend
        on the width of the arrow, because Matplotlib already takes
        this into account. See :trac:`12836`::

            sage: fig = Graphics().matplotlib()
            sage: sp = fig.add_subplot(1,1,1)
            sage: a = arrow((0,0), (1,1))
            sage: b = arrow((0,0), (1,1), width=20)
            sage: p1 = a[0]._render_on_subplot(sp)
            sage: p2 = b[0]._render_on_subplot(sp)
            sage: p1.shrinkA == p2.shrinkA
            True
            sage: p1.shrinkB == p2.shrinkB
            True

        Dashed arrows should have solid arrowheads,
        :trac:`12852`. This test saves the plot of a dashed arrow to
        an EPS file. Within the EPS file, ``stroke`` will be called
        twice: once to draw the line, and again to draw the
        arrowhead. We check that both calls do not occur while the
        dashed line style is enabled::

            sage: a = arrow((0,0), (1,1), linestyle='dashed')
            sage: filename = tmp_filename(ext='.eps')
            sage: a.save(filename=filename)
            sage: with open(filename, 'r') as f:
            ....:     contents = f.read().replace('\n', ' ')
            sage: two_stroke_pattern = r'setdash.*stroke.*stroke.*setdash'
            sage: import re
            sage: two_stroke_re = re.compile(two_stroke_pattern)
            sage: two_stroke_re.search(contents) is None
            True
        """
        options = self.options()
        head = options.pop('head')
        if head == 0: style = '<|-'
        elif head == 1: style = '-|>'
        elif head == 2: style = '<|-|>'
        else: raise KeyError('head parameter must be one of 0 (start), 1 (end) or 2 (both).')
        width = float(options['width'])
        arrowshorten_end = float(options.get('arrowshorten',0))/2.0
        arrowsize = float(options.get('arrowsize',5))
        head_width=arrowsize
        head_length=arrowsize*2.0
        color = to_mpl_color(options['rgbcolor'])
        from matplotlib.patches import FancyArrowPatch
        p = FancyArrowPatch((self.xtail, self.ytail), (self.xhead, self.yhead),
                            lw=width, arrowstyle='%s,head_width=%s,head_length=%s'%(style,head_width, head_length),
                            shrinkA=arrowshorten_end, shrinkB=arrowshorten_end,
                            fc=color, ec=color, linestyle=options['linestyle'])
        p.set_zorder(options['zorder'])
        p.set_label(options['legend_label'])

        if options['linestyle']!='solid':
            # The next few lines work around a design issue in matplotlib. Currently, the specified
            # linestyle is used to draw both the path and the arrowhead.  If linestyle is 'dashed', this
            # looks really odd.  This code is from Jae-Joon Lee in response to a post to the matplotlib mailing
            # list.  See http://sourceforge.net/mailarchive/forum.php?thread_name=CAG%3DuJ%2Bnw2dE05P9TOXTz_zp-mGP3cY801vMH7yt6vgP9_WzU8w%40mail.gmail.com&forum_name=matplotlib-users

            import matplotlib.patheffects as pe
            class CheckNthSubPath(object):
                def __init__(self, patch, n):
                    """
                    creates an callable object that returns True if the provided
                    path is the n-th path from the patch.
                    """
                    self._patch = patch
                    self._n = n

                def get_paths(self, renderer):
                    self._patch.set_dpi_cor(renderer.points_to_pixels(1.))
                    paths, fillables = self._patch.get_path_in_displaycoord()
                    return paths

                def __call__(self, renderer, gc, tpath, affine, rgbFace):
                    path = self.get_paths(renderer)[self._n]
                    vert1, code1 = path.vertices, path.codes
                    import numpy as np

                    if np.all(vert1 == tpath.vertices) and np.all(code1 == tpath.codes):
                        return True
                    else:
                        return False


#.........这里部分代码省略.........
开发者ID:felix-salfelder,项目名称:sage,代码行数:103,代码来源:arrow.py

示例4: draw_network

# 需要导入模块: from matplotlib.patches import FancyArrowPatch [as 别名]
# 或者: from matplotlib.patches.FancyArrowPatch import set_zorder [as 别名]
def draw_network(G, pos, node_color=None, ax=None,
                 radius=1.4, node_alpha=0.5, edge_alpha=0.25,
                 fontsize=12, only_nodes = None):
    """Improved drawing of directed graphs in NetworkX.

    Modified from http://groups.google.com/group/networkx-discuss/
    browse_thread/thread/170624d22c4b0ee6?pli=1.

    Author of original: Stefan van der Walt

    Parameters
    ----------
    pos : dictionary
      A dictionary with nodes as keys and positions as values.

    node_color : string or array of floats
      A single color format string, or a sequence of colors with an entry
      for each node in G.
    """
    if ax is None:
        f, ax = plt.subplots()

    if only_nodes is None:
        only_nodes = set(G.nodes())
        

    only_nodes = set(only_nodes) if not isinstance(only_nodes, set) else \
                 only_nodes

    # Find the set of all the nodes connected to the ones we want to highlight
    connected = set()
    for n in only_nodes:
        connected.update(G.predecessors(n) + G.successors(n))

    # Walk and draw nodes
    for i, n in enumerate(G.nodes()):
        if node_color is None:
            color = (0, 0, 0)
        else:
            color = node_color[n]
        #if node_color is None or cmap is None:
        #    color = (0,0,0)
        #else:
        #    color = cmap(node_color[n])

        # Selectively de-highlight nodes not being shown
        if n in only_nodes:
            t_alpha = 1.0
            n_alpha = node_alpha
            zorder = 2.2
        elif n in connected:
            t_alpha = n_alpha = 0.6*node_alpha
            zorder = 2.0
        else:
            t_alpha = n_alpha = 0.15*node_alpha
            zorder = 1.8

        c = Circle(pos[n],radius=radius,
                   alpha=n_alpha,
                   color=color,ec='k')
        x, y = pos[n]
        t = plt.text(x, y, n, horizontalalignment='center',
                     verticalalignment='center', color='k', fontsize=fontsize,
                     weight='bold', alpha=t_alpha)
        t.set_zorder(zorder+0.1)
        c = ax.add_patch(c)
        c.set_zorder(zorder)
        G.node[n]['patch']=c
        x,y=pos[n]

    # Walk and draw edges. Keep track of edges already seen to offset
    # multiedges and merge u<->v edges into one.
    
    seen={}
    for (u,v) in G.edges(data=False):
        if not (u in only_nodes or v in only_nodes):
            continue
        
        n1 = G.node[u]['patch']
        n2 = G.node[v]['patch']
        rad=0.1
        color = 'k'
    
        if (u,v) in seen:
            # For multiedges, offset new ones
            rad=seen.get((u,v))
            rad=(rad + np.sign(rad)*0.1)*-1

        # If the opposite edge had already been drawn, draw on the same line to
        # reduce clutter.
        if (v,u) in seen:
            arrowstyle = '<|-'
            c1, c2, pA, pB = n2.center, n1.center, n2, n1
        else:
            arrowstyle = '-|>'
            c1, c2, pA, pB = n1.center, n2.center, n1, n2
            
        e = FancyArrowPatch(c1, c2, patchA=pA, patchB=pB,
                            arrowstyle=arrowstyle,
                            connectionstyle='arc3,rad=%s'%rad,
#.........这里部分代码省略.........
开发者ID:MSenden,项目名称:CoCoTools,代码行数:103,代码来源:nxdraw.py


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