From 9b4db6b40f3cbcf76cff11989323ad2b12cba6f7 Mon Sep 17 00:00:00 2001
From: Maxim Gonchar <maxim.mg.gonchar@gmail.com>
Date: Fri, 19 May 2023 15:07:26 +0300
Subject: [PATCH] feat: plot(show, close) options

---
 model_tools/parameters_storage.py | 17 +++++++++++++++--
 models/dayabay_v0.py              |  4 +---
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/model_tools/parameters_storage.py b/model_tools/parameters_storage.py
index c1df67f..3b78f5b 100644
--- a/model_tools/parameters_storage.py
+++ b/model_tools/parameters_storage.py
@@ -28,13 +28,26 @@ class ParametersStorage(NestedMKDict):
             key = '.'.join(key)
             labels.setdefault('paths', []).append(key)
 
-    def plot(self) -> None:
+    def plot(
+        self,
+        *args,
+        close: bool=True,
+        show: bool=True,
+        **kwargs
+    ) -> None:
         from dagflow.plot import plot_auto
+        if close:
+            from matplotlib.pyplot import close
+        if show:
+            from matplotlib.pyplot import show
         for key, value in self.walkitems():
             if not isinstance(value, Output):
                 continue
 
-            plot_auto(value)
+            plot_auto(value, *args, **kwargs)
+
+            if show: show()
+            if close: close()
 
     def to_list(self, **kwargs) -> list:
         return self.visit(ParametersVisitor(kwargs)).data_list
diff --git a/models/dayabay_v0.py b/models/dayabay_v0.py
index 6b5e8c2..ea27d1c 100644
--- a/models/dayabay_v0.py
+++ b/models/dayabay_v0.py
@@ -1,6 +1,5 @@
 from dagflow.bundles.load_parameters import load_parameters
 from pathlib import Path
-from matplotlib.pyplot import show
 
 from dagflow.graph import Graph
 from dagflow.graphviz import savegraph
@@ -63,8 +62,7 @@ def model_dayabay_v0():
         outputs['edges.energy_common']= (energy_edges:=Array("energy_edges", linspace(0, 12, 241)).outputs[0])
 
     storage.read_paths()
-    storage('outputs').plot()
-    show()
+    storage('outputs').plot(close=False, show=True)
 
     storage['parameter.normalized.detector.eres.b_stat'].value = 1
     storage['parameter.normalized.detector.eres.a_nonuniform'].value = 2
-- 
GitLab