コード例 #1
0
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')
コード例 #2
0
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')
コード例 #3
0
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)