本文整理汇总了Python中pygraphviz.AGraph.string方法的典型用法代码示例。如果您正苦于以下问题:Python AGraph.string方法的具体用法?Python AGraph.string怎么用?Python AGraph.string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygraphviz.AGraph
的用法示例。
在下文中一共展示了AGraph.string方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DotRenderer
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import string [as 别名]
class DotRenderer(GraphRenderer):
"""Renderer fox dot."""
"""The AGraph used for rendering."""
_graph = None
def __init__(self, settings, reporter):
GraphRenderer.__init__(self, settings, reporter)
if not pygraphvizAvail:
self.reporter.severe("Can not render dot format because module `pygraphviz` cannot be loaded")
def prepare(self):
self._graph = AGraph(strict=False, directed=True,
name=self._visitor.sourceName)
def finish(self):
# TODO The ordering of nodes seems to be rather random in the output;
# however, the node ordering is used for the layout of the graph
# at least by `dot` and by `neato`; there should be a way to
# determine the ordering
r = self._graph.string()
self._graph = None
return r
def renderAnchor(self, anchor):
self._graph.add_node(anchor.id(), label=anchor.name())
def renderReference(self, reference):
if reference.fromAnchor is None:
# No anchor to start edge from
# TODO Should result in a warning
return
fromId = reference.fromAnchor.id()
toId = reference.toAnchor.id()
if self._doReverse:
(fromId, toId) = (toId, fromId)
self._graph.add_edge(fromId, toId)
示例2: __init__
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import string [as 别名]
#.........这里部分代码省略.........
def add_functional_edge(self, src, dst, name):
self.connected_nodes.add(src)
self.connected_nodes.add(dst)
self.graph.add_edge(
graphviz_id(src),
graphviz_id(dst),
label=name,
arrowhead="open",
headlabel="1...1",
taillabel="0...*",
labeldistance=2.0,
labelfontcolor="black",
labelangle=-65.0,
)
def add_inversefunctional_edge(self, src, dst, name):
self.connected_nodes.add(src)
self.connected_nodes.add(dst)
self.graph.add_edge(
graphviz_id(src),
graphviz_id(dst),
label=name,
arrowhead="open",
headlabel="0...*",
taillabel="1...1",
labeldistance=2.0,
labelfontcolor="black",
labelangle=-65.0,
)
def add_equivalentclass_edge(self, src, dst):
self.connected_nodes.add(src)
self.connected_nodes.add(dst)
self.graph.add_edge(
graphviz_id(src), graphviz_id(dst), label="\<\<equivalentClass\>\>", arrowhead="none", style="dashed"
)
def add_unionof_edge(self, src, dst):
self.connected_nodes.add(src)
self.connected_nodes.add(dst)
self.graph.add_edge(
graphviz_id(src), graphviz_id(dst), label="\<\<unionOf\>\>", arrowhead="open", style="dashed"
)
def add_oneof_edge(self, src, dst):
self.connected_nodes.add(src)
self.connected_nodes.add(dst)
self.graph.add_edge(
graphviz_id(src), graphviz_id(dst), label="\<\<instanceOf\>\>", arrowhead="open", style="dashed", dir="back"
)
def add_subclass_edge(self, src, dst):
self.connected_nodes.add(src)
self.connected_nodes.add(dst)
self.graph.add_edge(graphviz_id(src), graphviz_id(dst), arrowhead="empty")
def set_label(self, label):
self.graph.graph_attr["label"] = label
def start_subgraph(self, graph_name):
self.subgraph = self.graph.add_subgraph(name="cluster_%s" % graphviz_id(graph_name))
self.subgraph.graph_attr["label"] = graph_name
def add_undescribed_nodes(self):
s = self.connected_nodes - self.described_nodes
for node in s:
self.graph.add_node(graphviz_id(node), label=node)
def write_to_file(self, filename_dot):
f = open(filename_dot, "w")
f.write(self.graph.string())
print("dot file created: " + filename_dot)
def visualize(self, filename, namespaceList=None):
self.graph.layout(prog="dot")
self.graph.draw(filename)
if filename.endswith(".svg"):
self._add_links_to_svg_file(filename, namespaceList)
print("graphic file created: " + filename)
def _add_links_to_svg_file(self, output, namespaceList=None):
# SVG Datei anpassen
svg_string = open(output).read()
# Titel der SVG Datei anpassen
svg_string = svg_string.replace("%3", output)
# Hyperlinks mit den Internetseiten hinzufügen
for ns in namespaceList:
namespace = str(ns[0]) # Präfix des Namespaces
url = str(ns[1]) # URL des Namespaces
regex_str = """%s:(\w+)""" % namespace
regex = re.compile(regex_str)
svg_string = regex.sub("""<a xlink:href='%s\\1'>%s:\\1</a>""" % (url, namespace), svg_string)
# Datei schreiben
svg_file = open(output, "w")
svg_file.write(svg_string)
svg_file.close()
示例3: Hagberg
# 需要导入模块: from pygraphviz import AGraph [as 别名]
# 或者: from pygraphviz.AGraph import string [as 别名]
__author__ = """Aric Hagberg ([email protected])"""
from pygraphviz import AGraph
A = AGraph()
# set some default node attributes
A.node_attr['style'] = 'filled'
A.node_attr['shape'] = 'circle'
A.node_attr['fixedsize'] = 'true'
A.node_attr['fontcolor'] = '#FFFFFF'
# make a star in shades of red
for i in range( 16 ):
A.add_edge( 0, i )
n = A.get_node( i )
n.attr['fillcolor'] = "#%2x0000" % ( i * 16 )
n.attr['height'] = "%s" % ( i / 16.0 + 0.5 )
n.attr['width'] = "%s" % ( i / 16.0 + 0.5 )
print A.string() # print to screen
A.write( "star.dot" ) # write to simple.dot
print "Wrote star.dot"
A.draw( 'star.png', prog="circo" ) # draw to png using circo
print "Wrote star.png"
import matplotlib.pyplot as plt
a = plt.imread( 'star.png' )
plt.imshow( a )
plt.show()