'Plot topology colored by node placement'

def do_plot(self, _line):

    global nx, plt, graphviz_layout
    if (not nx):
        try:
            import networkx
            nx = networkx
            from matplotlib import pyplot
            plt = pyplot
            import pygraphviz
            assert pygraphviz
            if hasattr(nx, 'graphviz_layout'):
                graphviz_layout = nx.graphviz_layout
            else:
                graphviz_layout = nx.drawing.nx_agraph.graphviz_layout
        except ImportError:
            error('plot    requires    networkx,    matplotlib    and    pygraphviz    -    please    install    them    and    try    again\n')
            return
    g = nx.Graph()
    mn = self.mn
    servers = getattr(mn, 'servers', ['localhost'])
    (hosts, switches) = (mn.hosts, mn.switches)
    nodes = (hosts + switches)
    g.add_nodes_from(nodes)
    links = [(link.intf1.node, link.intf2.node) for link in self.mn.links]
    g.add_edges_from(links)
    color = dict(zip(servers, self.colorsFor(servers)))
    pos = graphviz_layout(g)
    opts = {'ax': None, 'font_weight': 'bold', 'width': 2, 'edge_color': 'darkblue'}
    hcolors = [color[getattr(h, 'server', 'localhost')] for h in hosts]
    scolors = [color[getattr(s, 'server', 'localhost')] for s in switches]
    nx.draw_networkx(g, pos=pos, nodelist=hosts, node_size=800, label='host', node_color=hcolors, node_shape='s', **opts)
    nx.draw_networkx(g, pos=pos, nodelist=switches, node_size=1000, node_color=scolors, node_shape='o', **opts)
    fig = plt.gcf()
    ax = plt.gca()
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)
    fig.canvas.set_window_title('Mininet')
    plt.title('Node    Placement', fontweight='bold')
    plt.show()
