本文整理汇总了Python中graphviz.Graph.attr方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.attr方法的具体用法?Python Graph.attr怎么用?Python Graph.attr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphviz.Graph
的用法示例。
在下文中一共展示了Graph.attr方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_graph
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import attr [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)
示例2: main
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import attr [as 别名]
def main():
SIZE = 20
PLOIDY = 2
MUTATIONS = 2
indices = range(SIZE)
# Build fake data
seqA = list("0" * SIZE)
allseqs = [seqA[:] for x in range(PLOIDY)] # Hexaploid
for s in allseqs:
for i in [choice(indices) for x in range(MUTATIONS)]:
s[i] = "1"
allseqs = [make_sequence(s, name=name) for (s, name) in \
zip(allseqs, [str(x) for x in range(PLOIDY)])]
# Build graph structure
G = Graph("Assembly graph", filename="graph")
G.attr(rankdir="LR", fontname="Helvetica", splines="true")
G.attr(ranksep=".2", nodesep="0.02")
G.attr('node', shape='point')
G.attr('edge', dir='none', penwidth='4')
colorset = get_map('Set2', 'qualitative', 8).mpl_colors
colorset = [to_hex(x) for x in colorset]
colors = sample(colorset, PLOIDY)
for s, color in zip(allseqs, colors):
sequence_to_graph(G, s, color=color)
zip_sequences(G, allseqs)
# Output graph
G.view()
示例3: outputToPdf
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import attr [as 别名]
def outputToPdf(graph, fileName,sourceLables):
e = Graph('NYC', filename=fileName, engine='dot')
e.body.extend(['rankdir=LR', 'size="100,100"'])
e.attr('node', shape='ellipse')
e.attr("node",color='green', style='filled')
edgeExists={}
for label in sourceLables:
e.node(str(label))
e.attr("node",color='lightblue2', style='filled')
for node in graph.nodeIter():
for edge in node.neighborsIter():
if not edge[1] in edgeExists:
e.attr("edge",labelcolor="blue")
e.edge(str(node.label()),edge[1],str(int(edge[0]))+"m")
edgeExists[node.label()]=1
edgeExists=None
e.body.append(r'label = "\nIntersections in New York City\n"')
e.body.append('fontsize=100')
e.view()
示例4: Graph
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import attr [as 别名]
#!/usr/bin/env python
# er.py - http://www.graphviz.org/content/ER
from graphviz import Graph
e = Graph('ER', filename='er.gv', engine='neato')
e.attr('node', shape='box')
e.node('course')
e.node('institute')
e.node('student')
e.attr('node', shape='ellipse')
e.node('name0', label='name')
e.node('name1', label='name')
e.node('name2', label='name')
e.node('code')
e.node('grade')
e.node('number')
e.attr('node', shape='diamond', style='filled', color='lightgrey')
e.node('C-I')
e.node('S-C')
e.node('S-I')
e.edge('name0', 'course')
e.edge('code', 'course')
e.edge('course', 'C-I', label='n', len='1.00')
e.edge('C-I', 'institute', label='1', len='1.00')
e.edge('institute', 'name1')
e.edge('institute', 'S-I', label='1', len='1.00')
示例5: Graph
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import attr [as 别名]
#!/usr/bin/env python
# http://www.graphviz.org/Gallery/gradient/g_c_n.html
from graphviz import Graph
g = Graph('G', filename='g_c_n.gv')
g.attr(bgcolor='purple:pink', label='agraph', fontcolor='white')
with g.subgraph(name='cluster1') as c:
c.attr(fillcolor='blue:cyan', label='acluster', fontcolor='white',
style='filled', gradientangle='270')
c.attr('node', shape='box', fillcolor='red:yellow',
style='filled', gradientangle='90')
c.node('anode')
g.view()
示例6: Graph
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import attr [as 别名]
dot.node('dead')
dot.edge('parrot', 'dead')
dot.graph_attr['rankdir'] = 'LR'
dot.edge_attr.update(arrowhead='vee', arrowsize='2')
dot.render(view=True)
################################################
### question c) and d)
################################################
## Shape corresponds to those used in previous tasks
g = Graph(name = 'mouse_cluster')
key_list = mids.keys() ## list of mouse IDs
for key in key_list:
g.attr('node', color=col[class_list.index(m_class[key])], shape = shp[class_list.index(m_class[key])]) ## setting node properties based of mouse class
g.node(key) ## Initialising node
for x in combinations(key_list,2):
if pearsonr(m_ave_values[x[0]],m_ave_values[x[1]])[0] > 0.98: ## Check for correlation score
g.edge(x[0], x[1], penwidth = str(0.03/float(1-pearsonr(m_ave_values[x[0]],m_ave_values[x[1]])[0]))) ## setting up edge, if the condition satisfies, to express the correlation score
g.view()
################################################
### question e)
################################################
## initialising graph
g = Graph(name = 'Alternate Mouse Cluster')
示例7: Draw
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import attr [as 别名]
class Draw(Toplevel):
"draw the tree to picture"
def __init__(self, parent):
"""
@ brief
initializa the Draw class
@ params
self -- new instance
"""
super(Draw, self).__init__(parent)
self.transient(parent)
self.title("current view")
self.grab_set()
def initDot(self):
"init the pane"
self.__dot = Graph()
self.__dot.format = "gif"
self.__dot.filename = "instance"
self.__dot.attr('node', shape="circle")
def setSource(self, source, with_label):
"set the source text"
self.node_suffix = 0
self.__tree = ast.literal_eval(source)
if with_label:
self.draw = self.__drawHasLabel
else:
self.draw = self.__drawNoLabel
def getTree(self):
"return the tree"
return self.__tree
def __drawNoLabel(self, tree, root="tree"):
"draw the tree without label on edge"
self.__dot.body.extend(["rank=same", "rankdir=TD"])
for key in tree.keys():
self.__dot.edge(root, key)
if type(tree[key]) is dict:
self.__drawNoLabel(tree[key], str(key))
else:
node_name = str(key) + str(self.node_suffix)
self.__dot.node(node_name, str(tree[key]))
self.__dot.edge(str(key), node_name)
self.node_suffix += 1
return self.__dot.pipe(format="gif")
def __drawHasLabel(self, tree):
"draw the tree with label on edge"
self.__dot.body.extend(["rank=same", "rankdir=TD"])
for key in tree.keys():
if type(tree[key]) is dict:
for key_ in tree[key]:
if type(tree[key][key_]) is dict:
child = next(iter(tree[key][key_].keys()))
self.__dot.edge(key, child, str(key_))
self.__drawHasLabel(tree[key][key_])
else:
node_name = str(key) + str(self.node_suffix)
self.__dot.node(node_name, tree[key][key_])
self.__dot.edge(key, node_name, str(key_))
self.node_suffix += 1
return self.__dot.pipe(format="gif")
def show(self):
"show the image"
tree = self.getTree()
image = self.draw(tree)
if image is not None:
label_image = PhotoImage(data=base64.b64encode(image))
image_label = Label(self, image=label_image)
image_label.photo = label_image
else:
image_label = Label(self, text="no image view")
image_label.pack()
self.wait_window(self)
示例8: print
# 需要导入模块: from graphviz import Graph [as 别名]
# 或者: from graphviz.Graph import attr [as 别名]
from graphviz import Graph
import pandas as pd
from os.path import join
my_dir = 'C:\\Users\\John\\Documents\\2016\\Python\\JiraStates'
full_jira_df = pd.read_csv(join(my_dir, 'jira_states.csv'))
# print(df)
issue_list = pd.Series.unique(full_jira_df["IssueNo"])
print(issue_list)
mygraph = Graph('ER', filename='test.gv', engine='circo')
# FIRST SET UP THE NODES
mygraph.attr('node', shape='ellipse', width='10')
mygraph.node('name0', label='name', color='red', width='10')
mygraph.node('name1', label='name')
#NOW JOIN THE NODES WITH EDGES
mygraph.edge('name0', 'name1', color='blue', dir='forward', edgetooltip='a tool tip')
#FINALLY DISPLAY THE GRAPH
mygraph.view()