Skip to content

Commit

Permalink
fix: ensure figures are closed when not shown in plotting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tuvelofstrom committed Nov 29, 2024
1 parent 38cc8cf commit f20a047
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/calibrated_explanations/_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f20a047

Please sign in to comment.