Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)
Plot the network 

        def plot_paths(network, show=False, save=True, paths = None):
    """ Plot the network """
#TODO: refactor out duplicated code from plot function
        import matplotlib.pyplot as plt
    except ImportError:
        LOG.warn("Matplotlib not found, not plotting using Matplotlib")
        import numpy
    except ImportError:
        LOG.warn("Matplotlib plotting requires numpy for graph layout")

    if not paths:
        paths = []

    plot_dir = config.plot_dir
    if not os.path.isdir(plot_dir):

    graph = network.graph

#Extract co-ordinates to normalize (needed for PathDrawer, desired for neatness in plots)
        x, y = zip(*[(d['x'], d['y']) for n, d in network.graph.nodes(data=True)])
        x = numpy.asarray(x, dtype=float)
        y = numpy.asarray(y, dtype=float)
#TODO: combine these two operations together
        x -= x.min()
        x *= 1.0/x.max() 
        y -= y.min()
        y *= -1.0/y.max() # invert
        y += 1 # rescale from 0->1 not 1->0
#TODO: see if can use reshape-type commands here
        co_ords = zip(list(x), list(y))
        co_ords = [numpy.array([x, y]) for x, y in co_ords]
        nodes = [n for n in network.graph.nodes()]
        pos = dict( zip(nodes, co_ords))

# Different node color for each AS. Use heatmap based on ASN

#Node colors
    legend = {
            'shapes': [],
            'labels': [],
    colormap = cm.jet
    unique_asn = sorted(list(set(d.asn for d in network.devices())))
    asn_norm = colors.normalize(0, len(unique_asn))
    asn_colors = dict.fromkeys(unique_asn)
    for index, asn in enumerate(asn_colors.keys()):
        asn_color = colormap(asn_norm(index)) #allocate based on index position
        asn_colors[asn] = asn_color
        legend['shapes'].append( plt.Rectangle((0, 0), 0.51, 0.51, 
            fc = asn_color))
        legend['labels'].append( asn)
    node_colors = [asn_colors[device.asn] for device in network.devices()]

    plot_graph(graph, title="Paths", pos=pos, show=show, save=save,
            paths = paths,

src/a/n/ank_le-HEAD/AutoNetkit/deploy/netkit_deploy.py   ank_le(Download)
#TODO: enable/disable this from command line/function default
        print "plotting paths", paths
        ank.plot_paths(self.network, paths = paths)