(x, name=None)
return "\n".join(walk(x, printer))
Display a directed graph of the Component structure of x

    :param x: A Component or Manager to graph
    :type  x: Component or Manager

    :param name: A name for the graph (defaults to x's name)
    :type  name: str

    @return: A directed graph representing x's Component structure.
    @rtype:  str
Display a directed graph of the Component structure of x
Display a directed graph of the Component structure of x
def graph(x, name=None):
    """Display a directed graph of the Component structure of x

    :param x: A Component or Manager to graph
    :type  x: Component or Manager

    :param name: A name for the graph (defaults to x's name)
    :type  name: str

    @return: A directed graph representing x's Component structure.
    @rtype:  str
    """

    networkx = tryimport("networkx")
    pygraphviz = tryimport("pygraphviz")
    plt = tryimport("matplotlib.pyplot", "pyplot")

    if networkx is not None and pygraphviz is not None and plt is not None:
        graph_edges = []
        for (u, v, d) in edges(x):
            graph_edges.append((u.name, v.name, float(d)))

        g = networkx.DiGraph()
        g.add_weighted_edges_from(graph_edges)

        elarge = [(u, v) for (u, v, d) in g.edges(data=True)
                  if d["weight"] > 3.0]
        esmall = [(u, v) for (u, v, d) in g.edges(data=True)
                  if d["weight"] <= 3.0]

        pos = networkx.spring_layout(g)  # positions for all nodes

        # nodes
        networkx.draw_networkx_nodes(g, pos, node_size=700)

        # edges
        networkx.draw_networkx_edges(g, pos, edgelist=elarge, width=1)
        networkx.draw_networkx_edges(
            g, pos, edgelist=esmall, width=1,
            alpha=0.5, edge_color="b", style="dashed"
        )

        # labels
        networkx.draw_networkx_labels(
            g, pos, font_size=10, font_family="sans-serif"
        )

        plt.axis("off")

        plt.savefig("{0:s}.png".format(name or x.name))
        networkx.write_dot(g, "{0:s}.dot".format(name or x.name))

        plt.clf()

    def printer(d, x):
        return "%s* %s" % (" " * d, x)

    return "\n".join(walk(x, printer))
def graph ( x , name = None ) : networkx = tryimport ( "networkx" ) pygraphviz = tryimport ( "pygraphviz" ) plt = tryimport ( "matplotlib.pyplot" , "pyplot" ) if networkx is not None and pygraphviz is not None and plt is not None : graph_edges = [ ] for ( u , v , d ) in edges ( x ) : graph_edges . append ( ( u . name , v . name , float ( d ) ) ) g = networkx . DiGraph ( ) g . add_weighted_edges_from ( graph_edges ) elarge = [ ( u , v ) for ( u , v , d ) in g . edges ( data = True ) if d [ "weight" ] > 3.0 ] esmall = [ ( u , v ) for ( u , v , d ) in g . edges ( data = True ) if d [ "weight" ] <= 3.0 ] pos = networkx . spring_layout ( g ) # positions for all nodes # nodes networkx . draw_networkx_nodes ( g , pos , node_size = 700 ) # edges networkx . draw_networkx_edges ( g , pos , edgelist = elarge , width = 1 ) networkx . draw_networkx_edges ( g , pos , edgelist = esmall , width = 1 , alpha = 0.5 , edge_color = "b" , style = "dashed" ) # labels networkx . draw_networkx_labels ( g , pos , font_size = 10 , font_family = "sans-serif" ) plt . axis ( "off" ) plt . savefig ( "{0:s}.png" . format ( name or x . name ) ) networkx . write_dot ( g , "{0:s}.dot" . format ( name or x . name ) ) plt . clf ( ) def printer ( d , x ) : return "%s* %s" % ( " " * d , x ) return "\n" . join ( walk ( x , printer ) )