当前位置: 首页>>代码示例>>Python>>正文


Python dot.write函数代码示例

本文整理汇总了Python中pygraph.readwrite.dot.write函数的典型用法代码示例。如果您正苦于以下问题:Python write函数的具体用法?Python write怎么用?Python write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了write函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_graphs_to_dots

    def write_graphs_to_dots(self):
        assert self.build_graph
        self._load_packages()

        from pygraph.readwrite import dot

        base = self.output_dir

        with open(join(base, 'digraph.dot'), 'w') as f:
            data = dot.write(self.digraph)
            f.write(data)

        with open(join(base, 'bfs.dot'), 'w') as f:
            (st, order) = breadth_first_search(self.digraph)
            bfs = digraph()
            bfs.add_spanning_tree(st)
            data = dot.write(bfs)
            f.write(data)

        with open(join(base, 'dfs.dot'), 'w') as f:
            (st, pre, post) = depth_first_search(self.digraph)
            dfs = digraph()
            dfs.add_spanning_tree(st)
            data = dot.write(dfs)
            f.write(data)
开发者ID:Studiogit,项目名称:conda,代码行数:25,代码来源:cran.py

示例2: test_dot_for_hypergraph

 def test_dot_for_hypergraph(self):
     gr = testlib.new_hypergraph()
     dotstr = dot.write(gr)
     gr1 = dot.read_hypergraph(dotstr)
     dotstr = dot.write(gr1)
     gr2 = dot.read_hypergraph(dotstr)  
     graph_equality(gr1, gr2)
开发者ID:soeltjen,项目名称:python-graph,代码行数:7,代码来源:unittests-readwrite.py

示例3: test_dot_for_digraph

 def test_dot_for_digraph(self):
     gr = testlib.new_digraph()
     dotstr = dot.write(gr)
     gr1 = dot.read(dotstr)
     dotstr = dot.write(gr1)
     gr2 = dot.read(dotstr)  
     graph_equality(gr1, gr2)
     assert len(gr.nodes()) == len(gr1.nodes())
     assert len(gr.edges()) == len(gr1.edges())
开发者ID:soeltjen,项目名称:python-graph,代码行数:9,代码来源:unittests-readwrite.py

示例4: test_output_names_in_dot

 def test_output_names_in_dot(self):
     gr1 = testlib.new_graph()
     gr1.name = "Some name 1"
     gr2 = testlib.new_digraph()
     gr2.name = "Some name 2"
     gr3 = testlib.new_hypergraph()
     gr3.name = "Some name 3"
     assert "Some name 1" in dot.write(gr1)
     assert "Some name 2" in dot.write(gr2)
     assert "Some name 3" in dot.write(gr3)
开发者ID:soeltjen,项目名称:python-graph,代码行数:10,代码来源:unittests-readwrite.py

示例5: run

	def run(self):
		#print "save graph in dir"
		gr = digraph()
		for x in self.nodes:
			gr.add_node(x.name)
		
		for x in self.nodes:
			x.addEdges(gr)
		
		dirLck.acquire()
		if not os.path.isdir(self.dir):
			if -1 == os.getcwd().find(self.dir):
				os.mkdir(self.dir)
		dirLck.release()
			
		if -1 == os.getcwd().find(self.dir):
			os.chdir(self.dir)

		dot = write(gr)
		f = open(self.filename, 'w')
		f.write(dot)
		f.close()

		proc = subprocess.Popen('dot -Tjpg ' + self.filename +' -o ' +  self.filename + '.jpg', shell=True, stdout=subprocess.PIPE,)
		r = proc.communicate()[0]
		print ""
开发者ID:burner,项目名称:probabilisticGuess,代码行数:26,代码来源:Graph.py

示例6: draw

    def draw(self, filename):
        print "initial state:", self.initial_state
        print "final states", self.final_state	
        print "transition table:", self.transition_table 

        vertexes = self.transition_table.keys()
        edges = self._edges()

        gr = digraph()        
        #gr.add_nodes([str(vertex) for vertex in vertexes])
        for vertex in vertexes:
            attrs = []
            
            if ((isinstance(self.final_state, list) and vertex in self.final_state) or
                    (isinstance(self.final_state, int) and vertex == self.final_state)):
                attrs.append('final')
            gr.add_node(str(vertex), attrs=attrs)

        for edge, label in edges.items():
            label = ', '.join(label)
            gr.add_edge(edge=edge, label=label)

        dot = write(gr)
        gvv = gv.readstring(dot)
        gv.layout(gvv, 'dot')
        gv.render(gvv, 'png', '%s.png' % filename)
开发者ID:afrolovskiy,项目名称:compilers_labs,代码行数:26,代码来源:fa.py

示例7: drawGraph

 def drawGraph(self, inputs):
     
     fileName = 'planetModel.png'
     gr = graph()
     self.addGraphNode(1,gr, inputs)
 # Draw as PNG
     #with open("./planetModel.viz", 'wb') as f:
         #dot = write(gr,f)
         #f.write(dot)
         #gvv = gv.readstring(dot)
         #gv.layout(gvv,'dot')
         #gv.render(gvv,'png', fileName)
         #f.close()
         
     gst = digraph()
     self.addGraphNode(1,gst, inputs)            
     with open("./planetModel.viz", 'wb') as f:            
         #st, order = breadth_first_search(gst, root=1)
         #gst2 = digraph()
         #gst2.add_spanning_tree(gst.nodes())
         #gst2.(1, 'post')
         dot = write(gst,f)
         f.write(dot)
         gvv = gv.readstring(dot)
         gv.layout(gvv,'dot')
         gv.render(gvv,'png', fileName)   
         f.close()         
         
         
          
     return fileName
开发者ID:jsrawan-mobo,项目名称:mrbigdata,代码行数:31,代码来源:planetModel.py

示例8: GraficarGrafo

	def GraficarGrafo(self, grafo, proy):
		grafof = self.GraficoProyecto(proy)
		dot = write(grafof)
		_gvv = _gv.readstring(dot)
		_gv.layout(_gvv,'dot')
		_gv.render(_gvv,'png',"sgs/public/images/grafo.png")
		return dict()
开发者ID:majito,项目名称:is2grupo06,代码行数:7,代码来源:item.py

示例9: graph_to_file

def graph_to_file(graph, filename='graph.png', delete_single=False):
    """Exports a graph to a image file.

    Params:
    graph - The graph to export.
    filename - The destination of the output. The filename should
               include an extention, the format of the file will always
               be PNG no matter what the extention is.
    delete_single - If set to true then all nodes without any neighbours
                    will be deleted prior to exporting the graph.
    """
    logger = logging.getLogger('.'.join((__name__, 'graph_to_file')))
    logger.info("Exporting a graph to %s", filename)

    # Delete nodes that don't have any neighbours
    if delete_single:
        del_nodes = [node for node in graph.nodes() if not graph.neighbors(node)]
        logger.info("Deleting %d nodes without neighbours", len(del_nodes))
        for node in del_nodes:
            graph.del_node(node)

    # Write the graph
    dot = graphtodot.write(graph)
    gvgraph = graphviz.graph_from_dot_data(dot)
    gvgraph.write(filename, format='png')
开发者ID:XeryusTC,项目名称:mapbots,代码行数:25,代码来源:exportimage.py

示例10: plot_graph

def plot_graph(gr):
    """
    draws the graph to file
    """
    p = 100.0 / (len(gr.nodes())+1)
    gr_ext = graph()

    
    for node in gr.nodes():
        if coin(p):
            if not gr_ext.has_node(node):
                gr_ext.add_node(node,attrs=gr.node_attributes(node))
            for n in [ ed[0] for ed in gr.edges() if ed[1] == node ]:
                if coin(0.3):
                    if not gr_ext.has_node(n):
                        gr_ext.add_node(n,attrs=gr.node_attributes(n))
                    #print "Edges:",gr_ext.edges()
                    if not gr_ext.has_edge((node,n)):
                        gr_ext.add_edge((node,n)) 
    dot = write(gr_ext)
    gvv = gv.readstring(dot)
    gv.layout(gvv,'dot')    
    if args[1]== 'karate.txt':
        gv.render(gvv,'png','community1.png') 
    elif args[1] == 'email.txt':
        gv.render(gvv,'png','community2.png')
    elif args[1] == 'hep-th-citations.txt':
        gv.render(gvv,'png','community3.png')
    elif args[1] == 'amazon1.txt':
        gv.render(gvv,'png','community4.png')
    elif args[1] == 'p2p-Gnutella30.txt':
        gv.render(gvv,'png','community5.png')
开发者ID:sarojinigarapati,项目名称:community-detection,代码行数:32,代码来源:main1.py

示例11: drawGraphFromSM

def drawGraphFromSM(SM, names, outFile):
	fig = plt.figure(1)
	plot1 = plt.imshow(SM, origin='upper', cmap=cm.gray, interpolation='nearest')
	plt.show()
		
	gr = graph()

	namesNew = []
	for i,f in enumerate(names):	
		if sum(SM[i,:])>0:
			gr.add_nodes([f])
			namesNew.append(f)
			
	Max = SM.max()
	Mean = mean(SM)

	Threshold = Mean * 1.5
	for i in range(len(names)):
		for j in range(len(names)):
			if i<j:
				if SM[i][j] > 0:
					gr.add_edge((names[i], names[j]))
	# Draw as PNG
	dot = write(gr)
	gvv = gv.readstring(dot)
	gv.layout(gvv,'dot')
	gv.render(gvv,'png', outFile)
开发者ID:tyiannak,项目名称:pyOpenAireTextClassifier,代码行数:27,代码来源:textFeatureExtraction.py

示例12: pruner_bakeoff

def pruner_bakeoff(nPoints, nSeeds, r0, delta, spread, lumpage, outputNameRoot):
    """
    Generate a graph, then use all the CANDIDATE_PRUNERS to prune it, and save the results for later investigation.
    """
    from spiralPointDistribution import spiralPointDistribution
    from pointsToOutwardDigraph import graphFromPoints
    #import matplotlib.pyplot as plot
    #import matplotlib.tri as tri    
    import pygraph.readwrite.dot as dotIO
    
    points = spiralPointDistribution(nPoints, nSeeds, r0, delta, spread, lumpage)
    
    outdir = os.path.dirname(outputNameRoot)
    if not os.path.exists(outdir):
        os.makedirs(outdir)
    
    #x, y = zip(*points)
    #plot.figure()
    #plot.gca().set_aspect('equal')
    #plot.triplot(tri.Triangulation(x, y), 'r,:')
    #plot.scatter(x, y)
    #plot.show()
    
    #NOT YET FINISHED
    #save png as outputNameRoot.prunerName.png (once I get Python graphviz bindings working)
    
    for pruner in CANDIDATE_PRUNERS:
        graph = graphFromPoints(points, nSeeds)
        graph = friendly_rename(graph)
        graph = pruner.prune(graph)
        dotstring = dotIO.write(graph)
        dotname = "{0}.{1}.gv".format(outputNameRoot, pruner.__class__.__name__)
        with open(dotname, "w") as dotfile:
            dotfile.write(dotstring)
开发者ID:BackupGGCode,项目名称:fake-data-generator,代码行数:34,代码来源:candidate_test_pruners.py

示例13: main

def main(args):
    g = generate(args.nodes, args.edges, True)

    while not find_cycle(g):
        g = generate(args.nodes, args.edges, True)

    with open(args.output, 'w') as f:
        f.write(write(g))
开发者ID:sash-ko,项目名称:graph-cd,代码行数:8,代码来源:generate_random.py

示例14: draw_pretty

def draw_pretty(pl, output_filename):
    gr = pygraph_build_pipeline_graph(pl)
    dot = write(gr)

    G = pgv.AGraph(dot, name=pl.name)
    prettify_graph(pl, G)
    G.layout(prog='dot')
    G.draw(output_filename)
开发者ID:mrmh2,项目名称:impip,代码行数:8,代码来源:plotpipe.py

示例15: save_as_pdf

def save_as_pdf(gr,filename,show_weights=False):

    from pygraph.readwrite.dot import write
    import gv
    dot = write(gr, weighted=show_weights)
    gvv = gv.readstring(dot)
    gv.layout(gvv,'fdp')
    gv.render(gvv,'pdf',filename)
开发者ID:Derano,项目名称:PCV,代码行数:8,代码来源:graphcut.py


注:本文中的pygraph.readwrite.dot.write函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。