Python networkx.graphviz_layout() Examples

The following are 12 code examples of networkx.graphviz_layout(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module networkx , or try the search function .
Example #1
Source File: script_bp_cut.py    From ibeis with Apache License 2.0 6 votes vote down vote up
def viz_factor_graph(gm):
    """
    ut.qtensure()
    gm = build_factor_graph(G, nodes, edges , n_annots, n_names, lookup_annot_idx,
                            use_unaries=True, edge_probs=None, operator='multiplier')
    """
    ut.qtensure()
    import networkx
    from networkx.drawing.nx_agraph import graphviz_layout
    networkx.graphviz_layout = graphviz_layout
    opengm.visualizeGm(gm, show=False, layout="neato", plotUnaries=True,
                        iterations=1000, plotFunctions=True,
                        plotNonShared=False, relNodeSize=1.0)

    _ = pt.show_nx(gm.G)  # NOQA

    # import utool
    # utool.embed()
    # infr = opengm.inference.Bruteforce
    # infr = opengm.inference.Bruteforce(gm, accumulator='maximizer')
    # # infr = opengm.inference.Bruteforce(gm, accumulator='maximizer')
    # # infr = opengm.inference.Bruteforce(gm, accumulator='integrator')
    # infr.infer()
    # print(infr.arg())
    # print(infr.value()) 
Example #2
Source File: __init__.py    From EDeN with MIT License 5 votes vote down vote up
def draw_adjacency_graph(adjacency_matrix,
                         node_color=None,
                         size=10,
                         layout='graphviz',
                         prog='neato',
                         node_size=80,
                         colormap='autumn'):
    """draw_adjacency_graph."""
    graph = nx.from_scipy_sparse_matrix(adjacency_matrix)

    plt.figure(figsize=(size, size))
    plt.grid(False)
    plt.axis('off')

    if layout == 'graphviz':
        pos = nx.graphviz_layout(graph, prog=prog)
    else:
        pos = nx.spring_layout(graph)

    if len(node_color) == 0:
        node_color = 'gray'
    nx.draw_networkx_nodes(graph, pos,
                           node_color=node_color,
                           alpha=0.6,
                           node_size=node_size,
                           cmap=plt.get_cmap(colormap))
    nx.draw_networkx_edges(graph, pos, alpha=0.5)
    plt.show()


# draw a whole set of graphs:: 
Example #3
Source File: pgm_viz.py    From ibeis with Apache License 2.0 5 votes vote down vote up
def draw_junction_tree(model, fnum=None, **kwargs):
    import plottool_ibeis as pt
    fnum = pt.ensure_fnum(fnum)
    pt.figure(fnum=fnum)
    ax = pt.gca()
    from pgmpy.models import JunctionTree
    if not isinstance(model, JunctionTree):
        netx_graph = model.to_junction_tree()
    else:
        netx_graph = model
    # prettify nodes
    def fixtupkeys(dict_):
        return {
            ', '.join(k) if isinstance(k, tuple) else k: fixtupkeys(v)
            for k, v in dict_.items()
        }
    n = fixtupkeys(netx_graph.nodes)
    e = fixtupkeys(netx_graph.edge)
    a = fixtupkeys(netx_graph.adj)
    netx_graph.nodes = n
    netx_graph.edge = e
    netx_graph.adj = a
    #netx_graph = model.to_markov_model()
    #pos = nx.nx_agraph.pygraphviz_layout(netx_graph)
    #pos = nx.nx_agraph.graphviz_layout(netx_graph)
    pos = nx.pydot_layout(netx_graph)
    node_color = [pt.NEUTRAL] * len(pos)
    drawkw = dict(pos=pos, ax=ax, with_labels=True, node_color=node_color,
                  node_size=2000)
    nx.draw(netx_graph, **drawkw)
    if kwargs.get('show_title', True):
        pt.set_figtitle('Junction / Clique Tree / Cluster Graph') 
Example #4
Source File: connection_strategy_simulator.py    From pydevp2p with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw(G, metrics=dict()):
    import matplotlib.pyplot as plt
    """
    dot - "hierarchical" or layered drawings of directed graphs. This is the default tool to use if edges have directionality.

    neato - "spring model'' layouts. This is the default tool to use if the graph is not too large (about 100 nodes) and you don't know anything else about it. Neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling.

    fdp - "spring model'' layouts similar to those of neato, but does this by reducing forces rather than working with energy.

    sfdp - multiscale version of fdp for the layout of large graphs.

    twopi - radial layouts, after Graham Wills 97. Nodes are placed on concentric circles depending their distance from a given root node.

    circo - circular layout, after Six and Tollis 99, Kauffman and Wiese 02. This is suitable for certain diagrams of multiple cyclic structures, such as certain telecommunications networks.

    """
    print 'layouting'

    text = ''
    for k, v in metrics.items():
        text += '%s: %.4f\n' % (k.ljust(max(len(x) for x in metrics.keys())), v)

    print text
    #pos = nx.graphviz_layout(G, prog='dot', args='')
    pos = nx.spring_layout(G)
    plt.figure(figsize=(8, 8))
    nx.draw(G, pos, node_size=20, alpha=0.5, node_color="blue", with_labels=False)
    plt.text(0.02, 0.02, text, transform=plt.gca().transAxes)  # , font_family='monospace')
    plt.axis('equal')
    outfile = 'network_graph.png'
    plt.savefig(outfile)
    print 'saved visualization to', outfile
    plt.ion()
    plt.show()
    while True:
        time.sleep(0.1) 
Example #5
Source File: visualization.py    From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _plot_graph(graph, filename=None, node_size=500):
    nx.draw_networkx(
        graph,
        nx.graphviz_layout(graph),
        node_size=node_size)
    if filename is None:
        pylab.show()
    else:
        pylab.savefig(filename) 
Example #6
Source File: visualization.py    From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _plot_graph(graph, filename=None, node_size=500):
    nx.draw_networkx(
        graph,
        nx.graphviz_layout(graph),
        node_size=node_size)
    if filename is None:
        pylab.show()
    else:
        pylab.savefig(filename) 
Example #7
Source File: visualization.py    From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _plot_graph(graph, filename=None, node_size=500):
    nx.draw_networkx(
        graph,
        nx.graphviz_layout(graph),
        node_size=node_size)
    if filename is None:
        pylab.show()
    else:
        pylab.savefig(filename) 
Example #8
Source File: visualization.py    From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _plot_graph(graph, filename=None, node_size=500):
    nx.draw_networkx(
        graph,
        nx.graphviz_layout(graph),
        node_size=node_size)
    if filename is None:
        pylab.show()
    else:
        pylab.savefig(filename) 
Example #9
Source File: visualization.py    From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _plot_graph(graph, filename=None, node_size=500):
    nx.draw_networkx(
        graph,
        nx.graphviz_layout(graph),
        node_size=node_size)
    if filename is None:
        pylab.show()
    else:
        pylab.savefig(filename) 
Example #10
Source File: visualization.py    From treeano with Apache License 2.0 5 votes vote down vote up
def _plot_graph(graph, filename=None, node_size=500):
    nx.draw_networkx(
        graph,
        nx.graphviz_layout(graph),
        node_size=node_size)
    if filename is None:
        pylab.show()
    else:
        pylab.savefig(filename) 
Example #11
Source File: bayes.py    From ibeis with Apache License 2.0 4 votes vote down vote up
def draw_tree_model(model, **kwargs):
    import plottool_ibeis as pt
    import networkx as netx
    if not ut.get_argval('--hackjunc'):
        fnum = pt.ensure_fnum(None)
        fig = pt.figure(fnum=fnum, doclf=True)  # NOQA
        ax = pt.gca()
        #name_nodes = sorted(ut.list_getattr(model.ttype2_cpds[NAME_TTYPE], 'variable'))
        netx_graph = model.to_markov_model()
        #pos = netx.pygraphviz_layout(netx_graph)
        #pos = netx.graphviz_layout(netx_graph)
        #pos = get_hacked_pos(netx_graph, name_nodes, prog='neato')
        pos = netx.nx_pydot.pydot_layout(netx_graph)
        node_color = [pt.WHITE] * len(pos)
        drawkw = dict(pos=pos, ax=ax, with_labels=True, node_color=node_color,
                      node_size=1100)
        netx.draw(netx_graph, **drawkw)
        if kwargs.get('show_title', True):
            pt.set_figtitle('Markov Model')

    if not ut.get_argval('--hackmarkov'):
        fnum = pt.ensure_fnum(None)
        fig = pt.figure(fnum=fnum, doclf=True)  # NOQA
        ax = pt.gca()
        netx_graph = model.to_junction_tree()
        # prettify nodes
        def fixtupkeys(dict_):
            return {
                ', '.join(k) if isinstance(k, tuple) else k: fixtupkeys(v)
                for k, v in dict_.items()
            }
        # FIXME
        n = fixtupkeys(netx_graph.node)
        e = fixtupkeys(netx_graph.edge)
        a = fixtupkeys(netx_graph.adj)
        netx_graph.nodes.update(n)
        netx_graph.edges.update(e)
        netx_graph.adj.update(a)
        #netx_graph = model.to_markov_model()
        #pos = netx.pygraphviz_layout(netx_graph)
        #pos = netx.graphviz_layout(netx_graph)
        pos = netx.nx_pydot.pydot_layout(netx_graph)
        node_color = [pt.WHITE] * len(pos)
        drawkw = dict(pos=pos, ax=ax, with_labels=True, node_color=node_color,
                      node_size=2000)
        netx.draw(netx_graph, **drawkw)
        if kwargs.get('show_title', True):
            pt.set_figtitle('Junction/Clique Tree / Cluster Graph') 
Example #12
Source File: graph.py    From costar_plan with Apache License 2.0 4 votes vote down vote up
def showGraph(root, filename='test.dot'):
    import matplotlib.pyplot as plt
    g, good, bad, mid = makeGraph(root)
    plt.figure(figsize=(10, 10), dpi=80)
    nx.write_dot(g, filename)

    # same layout using matplotlib with no labels
    pos = nx.graphviz_layout(g, prog='dot')

    nx.draw_networkx_edges(g, pos, width=1.0, alpha=1., arrows=False)
    ALPHA = 1.0
    colors = [(0.2, 0.8, 0.2)] * len(good)
    nx.draw_networkx_nodes(g, pos,
                           nodelist=good,
                           node_color=colors,
                           alpha=ALPHA,

                           node_shape='s',
                           node_size=1600)
    colors = [(0.9, 0.4, 0.4)] * len(bad)
    nx.draw_networkx_nodes(g, pos,
                           nodelist=bad,
                           node_color=colors,
                           alpha=ALPHA,
                           node_shape='8',
                           node_size=1600)
    colors = [(0.8, 0.8, 0.8)] * len(mid)
    nx.draw_networkx_nodes(g, pos,
                           nodelist=mid,
                           node_color=colors,
                           node_shape='s',
                           alpha=ALPHA,
                           node_size=1600)
    labels = {}
    lookup = {
        "NODE": "0",
        "Default": "D",
        "Left": "L",
        "Right": "R",
        "Pass": "P",
        "Stop": "S",
        "Wait": "W",
        "Follow": "F",
        "Finish": "C",
    }
    for name in good:
        labels[name] = lookup[name.split(' ')[0]]
    for name in bad:
        labels[name] = lookup[name.split(' ')[0]]
    for name in mid:
        labels[name] = lookup[name.split(' ')[0]]
    nx.draw_networkx_labels(g, pos, labels, font_size=20)

    plt.axis('off')
    plt.show()