Python networkx.write_dot() Examples

The following are 11 code examples of networkx.write_dot(). 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: build.py    From stolos with Apache License 2.0 6 votes vote down vote up
def visualize_dag(dg=None, plot_nx=False, plot_graphviz=True, write_dot=True,
                  prog='dot'):
    """For interactive use"""
    import webbrowser
    if not dg:
        dg = build_dag()
    dg = nx.relabel_nodes(
        dg,
        {x: "%s\n%s" % (x, node.get_job_id_template(x)[0]) for x in dg.node})
    if plot_nx:
        nx.draw_graphviz(dg, prog=prog)
    if write_dot or plot_graphviz:
        tmpf = tempfile.mkstemp(suffix='.dot', prefix='stolos_dag_')[1]
        nx.write_dot(dg, tmpf)
        os.popen('{1} {0} -Tpng > {0}.png'.format(tmpf, prog))
        print("saved to %s.png" % tmpf)
        if plot_graphviz:
            webbrowser.open(tmpf + '.png') 
Example #2
Source File: jvm_generate.py    From MARA_Framework with GNU Lesser General Public License v3.0 6 votes vote down vote up
def __init__(self, _analysis) :
        self.__analysis = _analysis

        try :
            from networkx import DiGraph
            from networkx import draw_graphviz, write_dot
        except ImportError :
            error("module networkx not found")

        self.__G = DiGraph()

        for m in self.__analysis.get_methods() :
            for bb in m.basic_blocks.get() :
                for trace in bb.stack_traces.get() :
                    for mre in jvm.MATH_JVM_RE :
                        if mre[0].match( trace[2].get_name() ) :
                            for i in trace[3].gets() :
                                self._add( str(i) ) 
Example #3
Source File: jvm_generate.py    From MARA_Framework with GNU Lesser General Public License v3.0 6 votes vote down vote up
def __init__(self, _analysis) :
        self.__analysis = _analysis

        try :
            from networkx import DiGraph
            from networkx import draw_graphviz, write_dot
        except ImportError :
            error("module networkx not found")

        self.__G = DiGraph()

        for m in self.__analysis.get_methods() :
            for bb in m.basic_blocks.get() :
                for trace in bb.stack_traces.get() :
                    for mre in jvm.MATH_JVM_RE :
                        if mre[0].match( trace[2].get_name() ) :
                            for i in trace[3].gets() :
                                self._add( str(i) ) 
Example #4
Source File: jvm_generate.py    From dr_droid with Apache License 2.0 6 votes vote down vote up
def __init__(self, _analysis) :
        self.__analysis = _analysis

        try :
            from networkx import DiGraph
            from networkx import draw_graphviz, write_dot
        except ImportError :
            error("module networkx not found")

        self.__G = DiGraph()

        for m in self.__analysis.get_methods() :
            for bb in m.basic_blocks.get() :
                for trace in bb.stack_traces.get() :
                    for mre in jvm.MATH_JVM_RE :
                        if mre[0].match( trace[2].get_name() ) :
                            for i in trace[3].gets() :
                                self._add( str(i) ) 
Example #5
Source File: takahe.py    From potara with MIT License 5 votes vote down vote up
def write_dot(self, dotfile):
        """ Outputs the word graph in dot format in the specified file. """
        nx.write_dot(self.graph, dotfile)
    #-B-----------------------------------------------------------------------B-

#~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
# ] Ending word_graph class
#~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~



#~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
# [ Class keyphrase_reranker
#~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
Example #6
Source File: jvm_generate.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def show(self) :
        print self.__G.node
        print self.__G.edge

        #draw_graphviz(self.__G)
        #write_dot(self.__G,'file.dot') 
Example #7
Source File: jvm_generate.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def show(self) :
        print self.__G.node
        print self.__G.edge

        #draw_graphviz(self.__G)
        #write_dot(self.__G,'file.dot') 
Example #8
Source File: jvm_generate.py    From dr_droid with Apache License 2.0 5 votes vote down vote up
def show(self) :
        print self.__G.node
        print self.__G.edge

        #draw_graphviz(self.__G)
        #write_dot(self.__G,'file.dot') 
Example #9
Source File: WGGraph.py    From AbTextSumm with Mozilla Public License 2.0 5 votes vote down vote up
def write_dot(self, dotfile):
        """ Outputs the word graph in dot format in the specified file. """
        nx.write_dot(self.graph, dotfile)
    #-B-----------------------------------------------------------------------B- 
Example #10
Source File: __init__.py    From pylhe with Apache License 2.0 5 votes vote down vote up
def visualize(event, outputname):
    g = nx.DiGraph()
    for i, p in enumerate(event.particles):
        g.add_node(i, attr_dict=p.__dict__)
        name = pypdt.particle(p.id).name
        greek = [
            "gamma",
            "nu",
            "mu",
            "tau",
            "rho",
            "Xi",
            "Sigma",
            "Lambda",
            "omega",
            "Omega",
            "Alpha",
            "psi",
            "phi",
            "pi",
            "chi",
        ]
        for greekname in greek:
            if greekname in name:
                name = name.replace(greekname, "\\" + greekname)
        if "susy-" in name:
            name = name.replace("susy-", "\\tilde ")
        g.node[i].update(texlbl="${}$".format(name))
    for i, p in enumerate(event.particles):
        for mom in p.mothers():
            g.add_edge(event.particles.index(mom), i)
    nx.write_dot(g, "event.dot")
    p = subprocess.Popen(["dot2tex", "event.dot"], stdout=subprocess.PIPE)
    tex2pix.Renderer(texfile=p.stdout).mkpdf(outputname)
    subprocess.check_call(["pdfcrop", outputname, outputname])
    os.remove("event.dot") 
Example #11
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()