Skip to content

Commit 53cd317

Browse files
author
Matthieu Ancellin
committed
Add more convenient function to save graph.
1 parent c0f3e82 commit 53cd317

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

labelled_functions/abstract.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def apply_in_namespace(self, namespace: Union[Dict[str, Any], xr.Dataset]) -> Un
173173
def _graph(self, **kwargs):
174174
pass
175175

176-
def graph(self, backend='graphviz', rankdir='LR'):
176+
def graph(self, backend='graphviz', rankdir='TB'):
177177
inputs_nodes, default_values, output_nodes, function_nodes, dummy_nodes, edges = self._graph()
178178

179179
if backend == 'graphviz':
@@ -227,3 +227,9 @@ def format_node_label(name, value):
227227

228228
return G
229229

230+
def save_graph(self, filepath=None):
231+
from pathlib import Path
232+
if filepath is None:
233+
filepath = Path.cwd() / (self.name + ".pdf")
234+
self.graph(backend='pygraphviz', rankdir='TB').draw(str(filepath), prog='dot')
235+

0 commit comments

Comments
 (0)