From 1a4bf722b9b04aa7d0ac79b078474fa0b6caccab Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Mon, 22 Jan 2024 09:21:46 +0000 Subject: [PATCH] correctly handle rc defaults --- src/mud/plot.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mud/plot.py b/src/mud/plot.py index c711cf9..6862bdd 100644 --- a/src/mud/plot.py +++ b/src/mud/plot.py @@ -22,7 +22,7 @@ def _check_latex(): """check latex installation""" - + original_params = plt.rcParams.copy() path = Path.cwd() / ".test_fig.png" try: # minimal example to trip up matplotlib plt.rcParams.update({"text.usetex": True}) @@ -35,9 +35,12 @@ def _check_latex(): except (RuntimeError, FileNotFoundError): _logger.warning("NOT USING TEX") return False + finally: + plt.rcParams.update(original_params) # Restore the original parameters + plt.close("all") # Close all figures to release any resources -# Matplotlib plotting options +# # Matplotlib plotting options HAS_LATEX = _check_latex() PREAMBLE = "" if HAS_LATEX: @@ -84,7 +87,6 @@ def save_figure( """ - global mud_plot_params fname = str(Path(save_path) / Path(fname)) plt.savefig(fname, **kwargs)