本文整理汇总了Python中graphviz.Source方法的典型用法代码示例。如果您正苦于以下问题:Python graphviz.Source方法的具体用法?Python graphviz.Source怎么用?Python graphviz.Source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphviz
的用法示例。
在下文中一共展示了graphviz.Source方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visualize_tree
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def visualize_tree(data,clf,clf_name):
features = data.columns
features = features[:-1]
class_names = list(set(data.iloc[:,-1]))
dot_data = tree.export_graphviz(clf, out_file=None, \
feature_names=features,class_names=class_names, \
filled=True, rounded=True, special_characters=True)
graph = graphviz.Source(dot_data)
graph.render('dtree_render_'+clf_name,view=True)
# Function to perform training with giniIndex.
示例2: dump_graph
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def dump_graph(dot_string,
show_svg=True,
dot_file_path='',
output_dot_string=False):
"""Output dot_string in various formats."""
if dot_file_path:
try:
dot_file = open(dot_file_path, "w+")
dot_file.write(dot_string)
dot_file.close()
except IOError:
print('Cannot open file: ' + dot_file_path)
if show_svg:
from IPython.display import display
from IPython.display import SVG
src = Source(dot_string)
display(SVG(src.pipe(format='svg')))
if output_dot_string:
return dot_string
return None
示例3: graphviz
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def graphviz(expr):
'''Plot sympy expression tree using graphviz
Args:
expr (sympy expression)
'''
return Source(dotprint(expr))
示例4: plot_tree
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def plot_tree(dot_data):
return graphviz.Source(dot_data)
示例5: visualize
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def visualize(self, graph_attrs=None, node_attrs=None, **kw):
from graphviz import Source
g = self.build_graph(**kw)
dot = g.to_dot(graph_attrs=graph_attrs, node_attrs=node_attrs,
result_chunk_keys={c.key for c in self.chunks})
return Source(dot)
示例6: get_svg
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def get_svg(self, dot_str):
import graphviz as gv
return gv.Source(dot_str, format='svg', engine=self.engine).pipe().decode('utf-8')
示例7: visualize_tree
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def visualize_tree(data,clf,clf_name):
features = data.columns
features = features[:-1]
class_names = list(set(data.iloc[:,-1]))
dot_data = tree.export_graphviz(clf, out_file=None, feature_names=features,class_names=class_names, filled=True, rounded=True, special_characters=True)
graph = graphviz.Source(dot_data)
graph.render('dtree_render_'+clf_name,view=True)
# Function to perform training with giniIndex.
示例8: load
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def load(self):
"""Load TensorFlow model into MIL program."""
logging.info("Loading TensorFlow model '{}'".format(self.model))
outputs = self.kwargs.get("outputs", None)
self._graph_def = self._graph_def_from_model(outputs)
if self._graph_def is not None and len(self._graph_def.node) == 0:
msg = "tf.Graph should have at least 1 node, Got empty graph."
raise ValueError(msg)
self._tf_ssa = self._tf_ssa_from_graph_def()
del self._graph_def
gc.collect()
if self.debug:
import graphviz
dot_string = self._tf_ssa.get_dot_string(
annotation=True, name_and_op_style=True, highlight_debug_nodes=[]
)
graphviz.Source(dot_string).view(
filename="/tmp/ssa_before_tf_passes", cleanup=True
)
program = self._program_from_tf_ssa()
logging.debug("program:\n{}".format(program))
return program
# @abstractmethod
示例9: _program_from_tf_ssa
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def _program_from_tf_ssa(self):
"""Overwrites TFLoader._mil_program_from_tf_ssa()"""
# Applying frontend passes on TFSSA. Note that these are different from
# passes applied to MIL in TF frontend.
tf_passes = [
delete_asserts,
functionalize_loops,
constant_propagation,
cond_to_where,
remove_variable_nodes,
fuse_dilation_conv,
]
if self.debug:
for tf_pass in _tqdm(
tf_passes, desc="Running TensorFlow Graph Passes", unit=" passes"
):
try:
tf_pass(self._tf_ssa)
except Exception as e:
logging.exception('Exception in pass "{}": {}'.format(tf_pass, e))
logging.info("Ignoring exception and continuing to next pass")
else:
for tf_pass in _tqdm(
tf_passes, desc="Running TensorFlow Graph Passes", unit=" passes"
):
tf_pass(self._tf_ssa)
if self.debug:
import graphviz
dot_string = self._tf_ssa.get_dot_string(
annotation=True, name_and_op_style=True, highlight_debug_nodes=[]
)
graphviz.Source(dot_string).view(
filename="/tmp/ssa_after_tf_passes", cleanup=True
)
converter = TFConverter(self._tf_ssa, **self.kwargs)
return converter.convert()
示例10: draw_text_graph
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def draw_text_graph(
words_to_machines, out_dir, fn='text', orig_machines=[]):
graph = MachineGraph.create_from_machines(
words_to_machines.values(), orig_machines=orig_machines)
src_str = graph.to_dot().encode('utf-8')
src = graphviz.Source(src_str, format='png')
pic_path = src.render(filename=fn, directory=out_dir)
return pic_path
示例11: draw_dep_graph
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def draw_dep_graph(deps, out_dir, fn):
dot_str = dep_to_dot(deps)
src = graphviz.Source(dot_str, format='png')
pic_path = src.render(filename=fn, directory=out_dir)
return pic_path
示例12: dot_to_img
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def dot_to_img(dot, file = 'report.png'):
import os
name, ext = os.path.splitext(file)
graph = graphviz.Source(dot)
graph.format = ext[1:]
graph.view(name, cleanup = True)
示例13: graph
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def graph(self, format='svg'):
try:
from graphviz import Source
except ImportError:
raise ImportError("You don't have graphviz package installed.\n"
"Please install graphviz or use write_file function to save dot file and generate the "
"graph manually.")
dot = self.generate()
graph = Source(dot)
graph.format = format
return graph
示例14: plot_model
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def plot_model(model, output, fig_name, fig_format):
"""
Plot neural network model architecture
:param model: network model
:param output: network output variable
:param fig_name: figure output name
:param format: figure format, such as "png", "pdf"
:return: dot file string
"""
var = make_dot(output, params=dict(model.named_parameters()))
s = Source(var, filename=fig_name, format=fig_format)
s.view()
return var
示例15: view_dot_graph
# 需要导入模块: import graphviz [as 别名]
# 或者: from graphviz import Source [as 别名]
def view_dot_graph(graph, filename=None, view=False):
"""
View the given DOT source. If view is True, the image is rendered
and viewed by the default application in the system. The file path of
the output is returned. If view is False, a graphviz.Source object is
returned. If view is False and the environment is in a IPython session,
an IPython image object is returned and can be displayed inline in the
notebook.
This function requires the graphviz package.
Args
----
- graph [str]: a DOT source code
- filename [str]: optional. if given and view is True, this specifies
the file path for the rendered output to write to.
- view [bool]: if True, opens the rendered output file.
"""
# Optionally depends on graphviz package
import graphviz as gv
src = gv.Source(graph)
if view:
# Returns the output file path
return src.render(filename, view=view)
else:
# Attempts to show the graph in IPython notebook
try:
__IPYTHON__
except NameError:
return src
else:
import IPython.display as display
format = 'svg'
return display.SVG(data=src.pipe(format))
# Ctypes binding