From f20a047b2c4acb0eae6b5f6aed876f2db7d4d389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuwe=20L=C3=B6fstr=C3=B6m?= <tuwe.lofstrom@ju.se> Date: Fri, 29 Nov 2024 18:25:48 +0100 Subject: [PATCH] fix: ensure figures are closed when not shown in plotting functions --- src/calibrated_explanations/_plots.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/calibrated_explanations/_plots.py b/src/calibrated_explanations/_plots.py index 59bee22..900eb33 100644 --- a/src/calibrated_explanations/_plots.py +++ b/src/calibrated_explanations/_plots.py @@ -130,7 +130,9 @@ def _plot_probabilistic(explanation, instance, predict, feature_weights, feature for ext in save_ext: fig.savefig(path + title + ext, bbox_inches='tight') if show: - fig.show() + plt.show() + else: + plt.close(fig) # pylint: disable=too-many-branches, too-many-statements, too-many-locals @@ -230,7 +232,9 @@ def _plot_regression(explanation, instance, predict, feature_weights, features_t for ext in save_ext: fig.savefig(path + title + ext, bbox_inches='tight') if show: - fig.show() + plt.show() + else: + plt.close(fig) # pylint: disable=duplicate-code @@ -288,6 +292,8 @@ def _plot_triangular(explanation, proba, uncertainty, rule_proba, rule_uncertain plt.savefig(path + title + ext, bbox_inches='tight') if show: plt.show() + else: + plt.close() # `__plot_triangular` def __plot_proba_triangle(): @@ -421,7 +427,9 @@ def _plot_alternative(explanation, instance, predict, feature_predict, features_ for ext in save_ext: fig.savefig(path + title + ext, bbox_inches='tight') if show: - fig.show() + plt.show() + else: + plt.close(fig) # pylint: disable=duplicate-code, too-many-branches, too-many-statements, too-many-locals