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


Python Graph.render方法代码示例

本文整理汇总了Python中graphviz.Graph.render方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.render方法的具体用法?Python Graph.render怎么用?Python Graph.render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphviz.Graph的用法示例。


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

示例1: create_interactions_graph

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def create_interactions_graph(clauses, f):
    dot = GGraph(comment='Interactions graph', engine='sfdp')
    seen_vars = set()
    edges_between_vars = defaultdict(int)

    for clause in clauses:
        for lit in clause:
            var = f(lit)
            if var not in seen_vars:
                seen_vars.add(var)
                dot.node(str(var), label=str(var))
    for clause in clauses:
        l = len(clause)
        for i in xrange(l):
            for j in xrange(i+1, l):
                edges_between_vars[(str(f(clause[i])), str(f(clause[j])))] += 1

    for interacting_vars, weight in edges_between_vars.iteritems():
        dot.edge(interacting_vars[0], interacting_vars[1], weight=str(weight))

    print edges_between_vars

    dot = _apply_styles(dot, styles)
    # print dot.source
    dot.render(os.path.join('images', 'interactions_graph.gv'), view=True)   
开发者ID:michal3141,项目名称:sat,代码行数:27,代码来源:interactions_graph.py

示例2: graph_data

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def graph_data(pkg_name):
    if not pkg_name:
        abort(404)

    filepath = os.path.join(cache_dir, pkg_name.lower())
    if not os.path.exists(filepath + '.png'):
        nodes, edges = reqs_graph(pkg_name)

        if not nodes:
            return redirect(url_for('static', filename='img/blank.png'))

        dot = Graph()
        dot.format = 'png'
        dot.node('0', nodes[0], fillcolor='#fbb4ae', style='filled', shape='box')
        for i, pkg_name in enumerate(nodes[1:]):
            dot.node(str(i+1), pkg_name, fillcolor='#ccebc5', style='filled')

        dot.edges([
            [str(i[0]), str(i[1])]
            for i in edges
        ])

        dot.render(filepath)

    return send_file(filepath + '.png')
开发者ID:sargo,项目名称:python-package-requirements,代码行数:27,代码来源:main.py

示例3: render_graph

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def render_graph(graph, name=None, directory=None, fill_infected='green3'):
    """ Render a user graph to an SVG file. Infected nodes are colored
    appropriately.

    Parameters:
    -----------
    graph : UserGraph
        The graph to render.

    name : str
        A name for the graph.

    directory : str
        The directory to render to.

    fill_infected : str
        The fill color for infected nodes.

    """
    dot = Graph(name=name, format='svg', strict=True)

    for user in graph.users():
        if user.metadata.get('infected', False):
            dot.attr('node', style='filled', fillcolor=fill_infected)

        dot.node(unicode(user.tag))
        dot.attr('node', style='')

    for user in graph.users():
        for neighbor in user.neighbors:
            dot.edge(unicode(user.tag), unicode(neighbor.tag))

    dot.render(directory=directory, cleanup=True)
开发者ID:brett-patterson,项目名称:ka-infection-interview,代码行数:35,代码来源:renderer.py

示例4: visualize_countries_together_in_item

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def visualize_countries_together_in_item(data, start_time_str=None, end_time_str=None, newspaper_str='*'):
    countries_together_dict = _get_countries_together_in_items(data)
    # print 'countries_together_dict:', countries_together_dict
    dot = Graph(comment='Countries together in item graph', engine='sfdp')
    seen_countries = set()
    edges_between_countries = defaultdict(int)

    ## Building the graph
    for ID_and_feed, countries in countries_together_dict.iteritems():
        countries_list = list(countries)
        for country in countries_list:
            if country != '' and country not in seen_countries:
                dot.node(country, label=country)
                seen_countries.add(country)
        for i in xrange(len(countries)):
            for j in xrange(i+1, len(countries)):
                fst = min(countries_list[i], countries_list[j])
                snd = max(countries_list[i], countries_list[j])
                edges_between_countries[(fst, snd)] += 1

    for edge_endpoints, edge_weight in edges_between_countries.iteritems():
        dot.edge(edge_endpoints[0], edge_endpoints[1], weight=str(edge_weight))

    print 'seen_countries:', seen_countries
    print 'edges_between_countries:', edges_between_countries

    
    dot = _apply_styles(dot, styles)
    # print dot.source
    out_dirname = newspaper_str.replace('*', '').replace('!', '').replace('[', '').replace(']', '')
    out_filename = ('countries_together_in_item_%s_%s.gv' % (start_time_str, end_time_str)).replace(':', '-')
    dot.render(os.path.join('images', out_dirname, out_filename), view=False)
开发者ID:michal3141,项目名称:geomedia,代码行数:34,代码来源:analyze.py

示例5: visualize

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
    def visualize(self):
        l = len(self.top_result)

        connections = dict()
        tags = dict()

        for i in range(l - 1):
            for j in range(1, l):
                if i != j:
                    key = (i, j)

                    message_list = self.get_message_list_between(self.top_result[i], self.top_result[j])
                    tag_cloud = self.subject.calculate_tag_cloud(message_list)

                    tags[key] = self.get_top_tag_cloud(tag_cloud, 5)

        # DOT language
        dot = GraphV(comment = "Information Flow - Enron")
        for i in range(l):
            dot.node(str(i), self.top_result[i] + " - " + self.company.get_role(self.top_result[i]))

        for (edge, tag) in tags.iteritems():
            node_1 = edge[0]
            node_2 = edge[1]
            note = ", ".join(tag)
            print note
            dot.edge(str(node_1), str(node_2), label=note)


        dot.render('test-output/round-table.gv', view=False)
开发者ID:npxquynh,项目名称:tts4,代码行数:32,代码来源:visualization.py

示例6: visual_decoding

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def visual_decoding(sent, saveto='tmp'):
    """
    Visualize multiple translation from machine translation.

    Example:
    >>> sentence = ['I have a apple',
                    'I have a dream',
                    'H have an egg']
    >>> visual_decoding(sent=sentence, saveto='demo')

    Args:
        sent: a list of str
            Multiple translations.

        saveto: str
            Graph will be saved as 'saveto.png'.

    Returns:
        None

    """
    graph = Graph(format='png',
                  node_attr={'shape':'box'},
                  graph_attr={'splines':'polyline'},
                  edge_attr={'dir':'forward'})

    graph.body.extend(['rankdir=LR'])

    for i,s in enumerate(sent):
        graph = _plot_sent(graph, s, flag=str(i))

    graph.render(filename=saveto, view=True)
开发者ID:whr94621,项目名称:VisualDecoding,代码行数:34,代码来源:visual_decoding.py

示例7: plot

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def plot(graph, engine='dot', filename='output/test'):
    """Possible engines: dot, neato, fdp, sfdp, twopi, circo"""
    g = Graph(format='png', engine=engine)
    for v in graph:
        g.node(str(index(v)))

    for v, w in graph.edges:
        g.edge(str(index(v)), str(index(w)))

    g.render(filename)
开发者ID:tennapel,项目名称:graph-problems,代码行数:12,代码来源:plot.py

示例8: generateGraph

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def generateGraph():
	G = Graph(
		engine = 'dot',
		filename = 'Btrfs-Graph.dot',
		name = 'BRTFS-Browser',
		comment = 'https://github.com/Zo0MER/BRTFS-Browser.git',
		graph_attr = {'rankdir': 'RL',
						'charset':'utf-8',
						'bgcolor':'#eeeeee',
						'labelloc':'t', 
						'splines':'compound',
						'nodesep':'0.7',
						'ranksep':'5'
					},
		node_attr = {'fontsize': '18.0',
					'shape':'box'
		}
	)

	#node with title and hyperlink on github
	G.node('meta', 
		label = 'Btrfs-debug-tree \nhttps://github.com/Zo0MER/BRTFS-Browser.git', 
		href = 'https://github.com/Zo0MER/BRTFS-Browser.git',
		fontcolor = '#4d2600',
		fontsize = '30.0'
		)

	first = inode[0]
	inode.remove(inode[0])

	if (inode):
		#link first item ROOT_TREE_DIR INODE_ITEM, INODE_REF with all INODE_ITEM EXTEND_DATA
		for pair in inode:
			G.edge(''.join([str(x) for x in first]), ''.join([str(x) for x in pair]))
	else:
		G.node(first)

	#save *.dot and others
	pathout = enterPath.get()
	filenameout = enterFilename.get()

	if (filenameout):
		filenameout = filenameout + '.gv.dot'
	else:
		filenameout = "btrfs-graph"

	G.filename = filenameout + '.gv.dot'
	G.directory = pathout

	G.save()
	for t in types:
		G.format = t
		G.render()
开发者ID:kekdck,项目名称:BRTFS-Browser,代码行数:55,代码来源:btrfs_graph.py

示例9: rev_del

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def rev_del(G,weights,count,Y,N):
  for i in range(m):
    gv = Graph('G', filename='rev_del',format='png')
    gv.node_attr.update(color='lightblue2', style='filled')
    gv.body.extend(['rankdir=LR'])
    for j in range(i+1,m):
      gv.edge(str(B[j][1]),str(B[j][2]),label=str(B[j][0]))
    for n in N: 
      gv.edge(str(B[n[3]][1]),str(B[n[3]][2]),label=str(B[n[3]][0]),color="red")
    for y in Y: 
      gv.edge(str(B[y[3]][1]),str(B[y[3]][2]),label=str(B[y[3]][0]),color="blue")
    gv.edge(str(B[i][1]),str(B[i][2]),label=str(B[i][0]),color="green")
    gv.render(str(count))
    count+=1
    count=Connectivity(G,weights[i],A,count,Y,N)
  return count
开发者ID:Premnath7,项目名称:set1,代码行数:18,代码来源:rev_del_gv.py

示例10: plot

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def plot(graph, engine='dot', filename='output/test', vertex_names={}):
    """
    Possible engines: dot, neato, fdp, sfdp, twopi, circo
    Vertex_names is an optional dict from vertices to strings.
    """
    g = Graph(format='png', engine=engine)

    def vertex_to_string(v):
        return (vertex_names[v] if v in vertex_names else '') + ' ({})'.format(str(index(v)))

    for v in graph:
        g.node(vertex_to_string(v))

    for v, w in graph.edges:
        g.edge(vertex_to_string(v), vertex_to_string(w))

    g.render(filename)
开发者ID:Chiel92,项目名称:graph-problems,代码行数:19,代码来源:plot.py

示例11: render

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
    def render(self, filename):
        """ Renders the graph to a file.

        Args:
            filename (str): Filename of the map file.
        """
        dot = Graph(comment='ISTravel graph', engine='fdp')
        for city in self.cities:
            dot.node(str(city))
        ploted = []
        for node in self.connections:
            for edge in self.connections[node]:
                if edge not in ploted:
                    ploted.append(edge)
                    dot.edge(
                        str(edge.nodes[0]),
                        str(edge.nodes[1]),
                        label=edge.transport[:2]
                    )
        dot.render(filename[:filename.rfind('.')]+".gv")
开发者ID:mamoit,项目名称:ai-search,代码行数:22,代码来源:routemap.py

示例12: create_conflicts_graph

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def create_conflicts_graph(clauses):
    dot = GGraph(comment='Conflicts graph', engine='sfdp')

    for i in xrange(len(clauses)):
        dot.node(str(i), label=str(i))

    for i in xrange(len(clauses)):
        for j in xrange(i+1, len(clauses)):
            clause_i = clauses[i]
            clause_j = clauses[j]
            edge_labels = []
            for lit in clause_i:
                if -lit in clause_j:
                    var = abs(lit)
                    edge_labels.append(str(var))
            if len(edge_labels) > 0:
                dot.edge(str(i), str(j), label=','.join(edge_labels)) 

    dot = _apply_styles(dot, styles)
    dot.render(os.path.join('images', 'conflicts_graph.gv'), view=True)
开发者ID:michal3141,项目名称:sat,代码行数:22,代码来源:interactions_graph.py

示例13: visualize_topics

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def visualize_topics(quora_data):
    dot = Graph(comment='Topics graph', engine='sfdp')
    seen_topics = set()
    for document in quora_data:
        question = _get_question(document)
        topics = document[question]['topics']
        # Iterating over topics and adding nodes for topics if necessary
        for topic in topics:
            if topic not in seen_topics:
                dot.node(topic, label=topic)
                seen_topics.add(topic)
        # Iterating over topics and adding edges between topics belonging to the same question
        for i in xrange(len(topics)):
            for j in xrange(i+1, len(topics)):
                dot.edge(topics[i], topics[j])
            #     topic1, topic2 in product(topics, topics):
            # dot.edge(topic1, topic2)
    dot = _apply_styles(dot, styles)
    # print dot.source
    dot.render(os.path.join('images', 'topics.gv'), view=True)
开发者ID:michal3141,项目名称:ed,代码行数:22,代码来源:explorer.py

示例14: main

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def main():
    source = sys.argv[1]
    with open(source, 'r') as infile:
        regions = json.load(infile)

    g = Graph('chroma', filename='chroma.graphview', format='png')
    for region in regions:
        name = region['name']
        style = {"style": "filled"}
        if "owner" in region:
            owner = region["owner"]
            if owner == 0:
                style["color"] = "orange"
            else:
                style["color"] = "blue"
                style["fontcolor"] = "white"

        g.node(name, **style)
        for conn in region['connections']:
            g.edge(name, conn)
    g.render()
开发者ID:atiaxi,项目名称:chromabot,代码行数:23,代码来源:graph.py

示例15: Connectivity

# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import render [as 别名]
def Connectivity(G,e,A,count,Y,N):  #checks connectivity of graph on removing edge e
  if A[0][0]==e:
    u=A[0][1]
    v=A[0][2]
    tup=A.pop(0)  
  index=len(B)-len(A)-1
  tup.append(index)
  G[u-1][v-1]=G[v-1][u-1]=0
  L=[]
  if path(G,u,v,u,L):
    N.append(tup)
    gv = Graph('G', filename='rev_del',format='png')
    gv.node_attr.update(color='lightblue2', style='filled')
    gv.body.extend(['rankdir=LR'])
    index=len(B)-len(A)-1
    for z in range(index+1,m):
      gv.edge(str(B[z][1]),str(B[z][2]),label=str(B[z][0]))
    for n in N: 
      gv.edge(str(B[n[3]][1]),str(B[n[3]][2]),label=str(B[n[3]][0]),color="red")
    for y in Y: 
      gv.edge(str(B[y[3]][1]),str(B[y[3]][2]),label=str(B[y[3]][0]),color="blue")
    gv.render(str(count))
    count+=1
    return count
  else:
    G[u-1][v-1]=G[v-1][u-1]=e
    Y.append(tup)
    gv = Graph('G', filename='rev_del',format='png')
    gv.node_attr.update(color='lightblue2', style='filled')
    gv.body.extend(['rankdir=LR'])
    index=len(B)-len(A)-1
    for z in range(index+1,m):
      gv.edge(str(B[z][1]),str(B[z][2]),label=str(B[z][0]))
    for n in N: 
      gv.edge(str(B[n[3]][1]),str(B[n[3]][2]),label=str(B[n[3]][0]),color="red")
    for y in Y: 
      gv.edge(str(B[y[3]][1]),str(B[y[3]][2]),label=str(B[y[3]][0]),color="blue")
    gv.render(str(count))
    count+=1
    return count
开发者ID:Premnath7,项目名称:set1,代码行数:42,代码来源:rev_del_gv.py


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