本文整理汇总了Python中pydot.graph_from_dot_data方法的典型用法代码示例。如果您正苦于以下问题:Python pydot.graph_from_dot_data方法的具体用法?Python pydot.graph_from_dot_data怎么用?Python pydot.graph_from_dot_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydot
的用法示例。
在下文中一共展示了pydot.graph_from_dot_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeGraph
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def writeGraph((elfgraph, filehash, imagedir, generatesvg)):
elfgraph_tmp = pydot.graph_from_dot_data(elfgraph)
if type(elfgraph_tmp) == list:
if len(elfgraph_tmp) == 1:
elfgraph_tmp[0].write_png(os.path.join(imagedir, '%s-graph.png' % filehash))
if generatesvg:
elfgraph_tmp[0].write_svg(os.path.join(imagedir, '%s-graph.svg' % filehash))
else:
elfgraph_tmp.write_png(os.path.join(imagedir, '%s-graph.png' % filehash))
if generatesvg:
elfgraph_tmp.write_svg(os.path.join(imagedir, '%s-graph.svg' % filehash))
## store variable names, function names from the ELF file
## along with the type, and so on. Also store the soname for
## the ELF file, as well as any RPATH values that might have
## been defined.
示例2: test_unicode_ids
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def test_unicode_ids(self):
node1 = '"aánñoöüé€"'
node2 = '"îôø®çßΩ"'
g = pydot.Dot()
g.set_charset('latin1')
g.add_node( pydot.Node( node1 ) )
g.add_node( pydot.Node( node2 ) )
g.add_edge( pydot.Edge( node1, node2 ) )
self.assertEqual( g.get_node(node1)[0].get_name(), node1 )
self.assertEqual( g.get_node(node2)[0].get_name(), node2 )
self.assertEqual( g.get_edges()[0].get_source(), node1 )
self.assertEqual( g.get_edges()[0].get_destination(), node2 )
graphs = pydot.graph_from_dot_data(g.to_string())
(g2,) = graphs
self.assertEqual( g2.get_node(node1)[0].get_name(), node1 )
self.assertEqual( g2.get_node(node2)[0].get_name(), node2 )
self.assertEqual( g2.get_edges()[0].get_source(), node1 )
self.assertEqual( g2.get_edges()[0].get_destination(), node2 )
示例3: print_tree
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def print_tree(tree, outfile, encoders):
"""
Print a tree to a file
Parameters
----------
tree :
the tree structure
outfile :
the output file
encoders :
the encoders used to encode categorical features
"""
import pydot
dot_data = StringIO()
export_graphviz(tree, encoders, filename=dot_data)
graph = pydot.graph_from_dot_data(dot_data.getvalue())
graph.write_pdf(outfile)
示例4: createTree
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def createTree(matrix,label):
kmeans = KMeans(n_clusters=moa_clusters, random_state=0).fit(matrix)
vector = map(int,kmeans.labels_)
pc_10 = int(len(querymatrix1)*0.01)
clf = tree.DecisionTreeClassifier(min_samples_split=min_sampsplit,min_samples_leaf=min_leafsplit,max_depth=max_d)
clf.fit(matrix,vector)
dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data,
feature_names=label,
class_names=map(str,list(set(sorted(kmeans.labels_)))),
filled=True, rounded=True,
special_characters=True,
proportion=False,
impurity=True)
out_tree = dot_data.getvalue()
out_tree = out_tree.replace('True','Inactive').replace('False','Active').replace(' ≤ 0.5', '').replace('class', 'Predicted MoA')
graph = pydot.graph_from_dot_data(str(out_tree))
try:
graph.write_jpg(output_name_tree)
except AttributeError:
graph = pydot.graph_from_dot_data(str(out_tree))[0]
graph.write_jpg(output_name_tree)
return
#initializer for the pool
示例5: line_dot
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def line_dot(self, code):
"""
%dot CODE - render code as Graphviz image
This line magic will render the Graphiz CODE, and render
it as an image.
Example:
%dot graph A { a->b };
"""
try:
import pydot
except:
raise Exception("You need to install pydot")
graph = pydot.graph_from_dot_data(str(code))
svg = graph.create_svg()
if hasattr(svg, "decode"):
svg = svg.decode("utf-8")
html = HTML(svg)
self.kernel.Display(html)
示例6: cell_dot
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def cell_dot(self):
"""
%%dot - render contents of cell as Graphviz image
This cell magic will send the cell to the browser as
HTML.
Example:
%%dot
graph A { a->b };
"""
try:
import pydot
except:
raise Exception("You need to install pydot")
graph = pydot.graph_from_dot_data(str(self.code))
svg = graph.create_svg()
if hasattr(svg, "decode"):
svg = svg.decode("utf-8")
html = HTML(svg)
self.kernel.Display(html)
self.evaluate = False
示例7: tree_image
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def tree_image(tree, fout=None):
try:
import pydot
except ImportError:
# make a hacky white plot
x = np.ones((10, 10))
x[0, 0] = 0
return x
dot_data = StringIO()
export_graphviz(tree, out_file=dot_data)
data = re.sub(r"gini = 0\.[0-9]+\\n", "", dot_data.getvalue())
data = re.sub(r"samples = [0-9]+\\n", "", data)
data = re.sub(r"\\nsamples = [0-9]+", "", data)
graph = pydot.graph_from_dot_data(data)
if fout is None:
fout = "tmp.png"
graph.write_png(fout)
return imread(fout)
示例8: method2format
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def method2format(output, _format="png", mx=None, raw=None):
"""
Export method to a specific file format
@param output : output filename
@param _format : format type (png, jpg ...) (default : png)
@param mx : specify the MethodAnalysis object
@param raw : use directly a dot raw buffer if None
"""
# pydot is optional!
import pydot
buff = "digraph {\n"
buff += "graph [rankdir=TB]\n"
buff += "node [shape=plaintext]\n"
if raw:
data = raw
else:
data = method2dot(mx)
# subgraphs cluster
buff += "subgraph cluster_{} ".format(hashlib.md5(bytearray(output, "UTF-8")).hexdigest())
buff += "{\n"
buff += "label=\"{}\"\n".format(data['name'])
buff += data['nodes']
buff += "}\n"
# subgraphs edges
buff += data['edges']
buff += "}\n"
d = pydot.graph_from_dot_data(buff)
if d:
for g in d:
getattr(g, "write_" + _format.lower())(output)
示例9: writeGraph
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def writeGraph((symbolgraph, filehash, counter, imagedir, generatesvg)):
symbolgraph_tmp = pydot.graph_from_dot_data(symbolgraph)
symbolgraph_tmp.write_png(os.path.join(imagedir, '%s-%d-kernel-symbol-graph.png' % (filehash, counter)))
if generatesvg:
symbolgraph_tmp.write_svg(os.path.join(imagedir, '%s-%d-kernel-symbol-graph.svg' % (filehash, counter)))
## extract, lookup and bundle information for kernel files
## * version
## * kernel symbols (both locally defined and needed from remote)
## * dependencies
示例10: test_attribute_with_implicit_value
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def test_attribute_with_implicit_value(self):
d='digraph {\na -> b[label="hi", decorate];\n}'
graphs = pydot.graph_from_dot_data(d)
(g,) = graphs
attrs = g.get_edges()[0].get_attributes()
self.assertEqual( 'decorate' in attrs, True )
示例11: test_graph_with_shapefiles
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def test_graph_with_shapefiles(self):
shapefile_dir = os.path.join(test_dir, 'from-past-to-future')
# image files are omitted from sdist
if not os.path.isdir(shapefile_dir):
warnings.warn('Skipping tests that involve images, '
'they can be found in the `git` repository.')
return
dot_file = os.path.join(shapefile_dir, 'from-past-to-future.dot')
pngs = [
os.path.join(shapefile_dir, fname) for
fname in os.listdir(shapefile_dir)
if fname.endswith('.png')]
f = open(dot_file, 'rt')
graph_data = f.read()
f.close()
#g = dot_parser.parse_dot_data(graph_data)
graphs = pydot.graph_from_dot_data(graph_data)
(g,) = graphs
g.set_shape_files( pngs )
jpe_data = g.create( format='jpe' )
hexdigest = sha256(jpe_data).hexdigest()
hexdigest_original = self._render_with_graphviz(
dot_file, encoding='ascii')
self.assertEqual( hexdigest, hexdigest_original )
示例12: test_multiple_graphs
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def test_multiple_graphs(self):
graph_data = 'graph A { a->b };\ngraph B {c->d}'
graphs = pydot.graph_from_dot_data(graph_data)
n = len(graphs)
assert n == 2, n
names = [g.get_name() for g in graphs]
assert names == ['A', 'B'], names
示例13: createTree
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def createTree(matrix,label):
vector = [1] * len(querymatrix1) + [0] * len(querymatrix2)
ratio = float(len(vector)-sum(vector))/float(sum(vector))
sw = np.array([ratio if i == 1 else 1 for i in vector])
pc_10 = int(len(querymatrix1)*0.01)
clf = tree.DecisionTreeClassifier(min_samples_split=min_sampsplit,min_samples_leaf=min_leafsplit,max_depth=max_d)
clf.fit(matrix,vector)
dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data,
feature_names=label,
class_names=['File2','File1'],
filled=True, rounded=True,
special_characters=True,
proportion=False,
impurity=True)
out_tree = dot_data.getvalue()
out_tree = out_tree.replace('True','Inactive').replace('False','Active').replace(' ≤ 0.5', '')
graph = pydot.graph_from_dot_data(str(out_tree))
try:
graph.write_jpg(output_name_tree)
except AttributeError:
graph = pydot.graph_from_dot_data(str(out_tree))[0]
graph.write_jpg(output_name_tree)
return
#initializer for the pool
示例14: method2format
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def method2format(output, _format="png", mx=None, raw=None):
"""
Export method to a specific file format
@param output : output filename
@param _format : format type (png, jpg ...) (default : png)
@param mx : specify the MethodAnalysis object
@param raw : use directly a dot raw buffer if None
"""
try:
import pydot
except ImportError:
error("module pydot not found")
buff = "digraph {\n"
buff += "graph [rankdir=TB]\n"
buff += "node [shape=plaintext]\n"
if raw:
data = raw
else:
data = method2dot(mx)
# subgraphs cluster
buff += "subgraph cluster_" + hashlib.md5(output).hexdigest() + " {\nlabel=\"%s\"\n" % data['name']
buff += data['nodes']
buff += "}\n"
# subgraphs edges
buff += data['edges']
buff += "}\n"
d = pydot.graph_from_dot_data(buff)
if d:
getattr(d, "write_" + _format.lower())(output)
示例15: method2format
# 需要导入模块: import pydot [as 别名]
# 或者: from pydot import graph_from_dot_data [as 别名]
def method2format( output, _format="png", mx = None, raw = False ) :
"""
Export method to a specific file format
@param output : output filename
@param _format : format type (png, jpg ...) (default : png)
@param mx : specify the MethodAnalysis object
@param raw : use directly a dot raw buffer
"""
try :
import pydot
except ImportError :
error("module pydot not found")
buff = "digraph code {\n"
buff += "graph [bgcolor=white];\n"
buff += "node [color=lightgray, style=filled shape=box fontname=\"Courier\" fontsize=\"8\"];\n"
if raw == False :
buff += method2dot( mx )
else :
buff += raw
buff += "}"
d = pydot.graph_from_dot_data( buff )
if d :
getattr(d, "write_" + _format)( output )