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


Python PatchCollection.zorder方法代码示例

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


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

示例1: draw

# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import zorder [as 别名]
def draw(options, H, points, convex=None):
    fig = MyFig(options, figsize=(10,8), xlabel='', ylabel='', legend=False, grid=False, aspect='auto')
    poly = Polygon(H, edgecolor='red', facecolor='red', closed=True, alpha=0.3)
    patch_collection = PatchCollection([poly], match_original=True)
    patch_collection.zorder = -2
    fig.ax.add_collection(patch_collection)

    for x, y in H:
        fig.ax.plot(x, y, marker='o', color='red')

    for x, y in [p for p in points if p not in H]:
        fig.ax.plot(x, y, marker='o', color='black')

    if convex != None:
        poly = Polygon(convex, edgecolor='blue', facecolor='none', closed=True, alpha=0.3)
        patch_collection = PatchCollection([poly], match_original=True)
        patch_collection.zorder = -2
        fig.ax.add_collection(patch_collection)

    fig.ax.axis((0, 1, 0, 1))
    fig.save('test')
开发者ID:Dekue,项目名称:des-routing-algorithms,代码行数:23,代码来源:concave-hull.py

示例2: plot

# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import zorder [as 别名]
def plot(r_data, fit_data, options):
    for sources in [10, 30, 50, 70, 90]:
        def add_legend():
            proxies = []
            for key in sorted(points.keys()):
                r = Rectangle((0, 0), 1, 1, facecolor=name2color(key), edgecolor='gray', alpha=0.5)
                proxies.append((r, key))
            fig.ax.legend([proxy for proxy, label in proxies], [name2label(label) for proxy, label in proxies], loc='lower right', labelspacing=0.1)
            fig.legend = True

        fig = MyFig(options, figsize=(10,8), xlabel=r'Fraction of Forwarded Packets~$\forwarded$', ylabel=r'Reachability~$\reachability$', legend=False, grid=False, aspect='auto', legend_pos='best')
        ellipses = list()

        points = {
            'gossip0': list(),
            'gossip3': list(),
            'gossip14': list(),
            'mcds': list(),
            'mpr-event': list(),
            'mpr-periodic': list()
        }

        def name2label(name):
            mapping = {
                'gossip0': r'\emph{gossip0}',
                'gossip3': r'\emph{gossip3}',
                'gossip14': r'counter-based',
                'mcds': r'$\MCDS$',
                'mpr-event': r'$\MPR$ (event-based)',
                'mpr-periodic': r'$\MPR$ (periodic)'
            }
            try:
                return mapping[name]
            except KeyError:
                return name

        def name2color(name):
            names = ['gossip0', 'gossip3', 'gossip14', 'mcds', 'mpr-event', 'mpr-periodic']
            if options['grayscale']:
                colors = options['graycm'](pylab.linspace(0, 1, len(names)))
            else:
                colors = fu_colormap()(pylab.linspace(0, 1, len(names)))
            try:
                i = names.index(name)
                return colors[i]
            except ValueError:
                return 'black'

        for t, a, b, value in fit_data:
            data = [(_N, _R, _R_conf, _F_conf) for _t, _N, _value, _R, _R_conf, _F_conf in r_data if t == _t and value == _value and _N == sources]
            if len(data) == 0:
                logging.warning('skipping: t=%s, value=%s, N=%d', str(t), str(value), sources)
                continue
            N, R, R_conf, F_conf = data[0]
            x = pylab.linspace(0, 1, 1000)
            if options['plot_fits']:
                fig.ax.plot(x, numpy.polyval([a, b], x), linestyle='solid', color='gray', alpha=0.4)
            plist = points[t]
            color = name2color(t)
            FW = (R-b)/a
            if R_conf != None and F_conf != None:
                ellipse = Ellipse((FW, R), float(F_conf)*2, float(R_conf)*2, edgecolor=color, facecolor=color, alpha=0.5)
                ellipses.append(ellipse)
                plist.append((FW+float(F_conf), R+float(R_conf)))
                plist.append((FW-float(F_conf), R+float(R_conf)))
                plist.append((FW+float(F_conf), R-float(R_conf)))
                plist.append((FW-float(F_conf), R-float(R_conf)))
            if options['plot_points']:
                fig.ax.plot(FW, R, marker='o', color=color, label='%s, $%s$' % (t, value))
        if options['plot_ellipses']:
            patch_collection = PatchCollection(ellipses, match_original=True)
            fig.ax.add_collection(patch_collection)

        for key, value in points.iteritems():
            if len(value) == 0:
                continue
            concave, convex = get_concave(value, 0.1)
            color = name2color(key)

            if options['plot_convex']:
                poly = Polygon(convex, edgecolor='gray', facecolor=color, closed=True, alpha=0.5)
                patch_collection = PatchCollection([poly], match_original=True)
                patch_collection.zorder = -2
                fig.ax.add_collection(patch_collection)

            if options['plot_concave']:
                poly = Polygon(concave, edgecolor='gray', facecolor=color, closed=True, alpha=0.5)
                patch_collection = PatchCollection([poly], match_original=True)
                patch_collection.zorder = -2
                fig.ax.add_collection(patch_collection)
        fig.ax.axis((0, 1, 0, 1))
        add_legend()
        fig.save('%d_sources' % sources)
开发者ID:Dekue,项目名称:des-routing-algorithms,代码行数:95,代码来源:comparison.py


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