本文整理匯總了Python中graphviz.Graph.add方法的典型用法代碼示例。如果您正苦於以下問題:Python Graph.add方法的具體用法?Python Graph.add怎麽用?Python Graph.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類graphviz.Graph
的用法示例。
在下文中一共展示了Graph.add方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: model_to_dot
# 需要導入模塊: from graphviz import Graph [as 別名]
# 或者: from graphviz.Graph import add [as 別名]
def model_to_dot(model):
g = Graph(name=model.name)
for comp in model.compartments:
gcomp = compartment_to_dot(comp)
gcomp.subgraph = True
gcomp.tag('::'+comp.id)
g.add(gcomp)
if model.get_param('FORCE_LABELS'):
g.add(AttrStmt('graph',forcelabels="true"))
return g
示例2: subsystem_to_dot
# 需要導入模塊: from graphviz import Graph [as 別名]
# 或者: from graphviz.Graph import add [as 別名]
def subsystem_to_dot(subsystem):
clone_links = clone_mets(subsystem)
g = Graph(name=subsystem.id)
if subsystem.get_param('CLUSTER_SUBSYSTEMS'):
g.cluster = True
style = subsystem.get_param('SUBSYSTEM_BORDER_STYLE')
g.add(AttrStmt('graph',style=style))
for rxn in subsystem.reactions:
g.add(reaction_to_dot(rxn))
g.add(AttrStmt('graph',label=subsystem.name,
fontsize=subsystem.get_param('SUBSYSTEM_FONTSIZE')))
if clone_links:
g.add(clone_links)
return g
示例3: compartment_to_dot
# 需要導入模塊: from graphviz import Graph [as 別名]
# 或者: from graphviz.Graph import add [as 別名]
def compartment_to_dot(compartment):
g = Graph(name=compartment.id,cluster=True,subgraph=True)
for subsystem in compartment.subsystems:
gsub = subsystem_to_dot(subsystem)
gsub.subgraph = True
gsub.tag('::'+subsystem.id)
g.add(gsub)
for comp in compartment.compartments:
gcomp = compartment_to_dot(comp)
gcomp.subgraph = True
gcomp.tag('::'+comp.id)
g.add(gcomp)
label = AttrStmt('graph',label=compartment.name,
fontsize=compartment.get_param('COMPARTMENT_FONTSIZE'))
g.add(label)
SHOW_EXCHANGES = compartment.get_param('SHOW_EXCHANGES')
if SHOW_EXCHANGES and compartment.local_exchanges:
gex = Graph(name=compartment.id+"::EX",cluster=True)
gex.add(g)
gex.add(AttrStmt('graph',style="dotted"))
for ex in compartment.local_exchanges:
gex.add(exchange_to_dot(ex))
return gex
else:
return g
示例4: old_reaction_to_dot
# 需要導入模塊: from graphviz import Graph [as 別名]
# 或者: from graphviz.Graph import add [as 別名]
def old_reaction_to_dot(rxn):
if not rxn.get_param('SHOW_MINORS') or rxn.get_param('MAX_MINORS') == 0:
return reaction_to_dot_simple(rxn)
INVISIBLE_NODE_ATTRS = rxn.get_param('INVISIBLE_NODE_ATTRS')
EDGE_ATTRS = rxn.get_param('EDGE_ATTRS')
MET_ATTRS = rxn.get_param('MET_ATTRS')
CURR_MET_ATTRS = rxn.get_param('CURR_MET_ATTRS')
ADD_MAJOR_LINKS = rxn.get_param('ADD_MAJOR_LINKS')
if rxn.has_param("MAX_MINORS"):
max_minors = rxn.get_param("MAX_MINORS")
if (len(rxn.minor_reactants) > max_minors
or len(rxn.minor_products) > max_minors):
# prevent this change from existing effecting the original rxn
rxn = copy.deepcopy(rxn)
rxn.consolidate_minors(max_minors)
def make_id():
curr = 0
while True:
yield "$" + rxn.id + "::" + str(curr)
curr += 1
ids = make_id()
LINK_EDGE_ATTRS = dict(len=0.5,weight=2.0,style="invisible")
MINOR_EDGE_ATTRS = dict(len=0.5,weight=2.0)
PULL_EDGE_ATTRS = dict(len=0.5,weight=0.1,style="invisible")
n_major_react = len(rxn.major_reactants)
n_minor_react = len(rxn.minor_reactants)
n_major_prod = len(rxn.major_products)
n_minor_prod = len(rxn.minor_products)
compact = rxn.get_param("COMPACT")
statements = []
statements.append(AttrStmt("edge",**EDGE_ATTRS))
if (n_major_react == n_major_prod == 1
and n_minor_react == n_minor_prod == 0):
statements.append(AttrStmt("node",**MET_ATTRS))
statements.append(Edge(rxn.major_reactants[0].id,
rxn.major_products[0].id,
dir="forward",id=ids.next()))
return statements
out_r_cent,r_cent,p_cent,out_p_cent = ["${0}::{1}".format(x,rxn.id)
for x in ("or","r","p","op")]
if n_major_react + n_minor_react == 1:
out_r_cent = r_cent = p_cent
if n_major_prod + n_minor_prod == 1:
out_p_cent = p_cent = r_cent
if compact or (n_major_react + n_minor_react <= 2):
out_r_cent = r_cent
if compact or (n_major_prod + n_minor_prod <= 2):
out_p_cent = p_cent
curr_name = lambda name: name + "@" + rxn.id
cluster = Graph(name="cluster_"+rxn.id,subgraph=True)
cluster.add(AttrStmt("graph",color="transparent",ordering="in"))
cluster.add(AttrStmt("node",**INVISIBLE_NODE_ATTRS))
for center in set((out_r_cent,r_cent,p_cent,out_p_cent)):
cluster.add(Node(center,**INVISIBLE_NODE_ATTRS))
cluster.add(AttrStmt("node",**CURR_MET_ATTRS))
for minor in rxn.minor_reactants:
cluster.add(Edge(curr_name(minor.id),r_cent,
id=ids.next(),**MINOR_EDGE_ATTRS))
if ADD_MAJOR_LINKS and out_r_cent != r_cent:
# pin the node
cluster.add(Edge(curr_name(minor.id),out_r_cent,
**LINK_EDGE_ATTRS))
if out_r_cent != r_cent:
cluster.add(Edge(out_r_cent,r_cent,len=0.5,id=ids.next()))
for minor in rxn.minor_products:
cluster.add(Edge(p_cent,curr_name(minor.id),dir="forward",
id=ids.next(),**MINOR_EDGE_ATTRS))
if ADD_MAJOR_LINKS and out_p_cent != r_cent:
cluster.add(Edge(out_p_cent,curr_name(minor.id),
id=ids.next(),**LINK_EDGE_ATTRS))
if out_p_cent != p_cent:
cluster.add(Edge(p_cent,out_p_cent,len=0.5,id=ids.next()))
if p_cent != r_cent:
cluster.add(Edge(p_cent,r_cent,len=0.5,id=ids.next()))
statements.append(cluster)
statements.append(AttrStmt("node",**MET_ATTRS))
for major in rxn.major_reactants:
statements.append(Edge(major.id,out_r_cent,id=ids.next()))
for major in rxn.major_products:
statements.append(Edge(out_p_cent,major.id,
dir="forward",id=ids.next()))
if ADD_MAJOR_LINKS:
# pull the products and reactants closer together
for l,r in zip(rxn.major_reactants[0:-1],rxn.major_reactants[1:]):
statements.append(Edge(l.id,r.id,**PULL_EDGE_ATTRS))
#.........這裏部分代碼省略.........