Skip to content

Commit ee77a7b

Browse files
authored
Merge pull request #15724 from rmcdermo/master
Python: add close figs to safe_run; proper handling of clear figure in fdsplotlib; list scatplots during processing
2 parents d3fcdf7 + 3c2569a commit ee77a7b

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

Utilities/Python/FDS_validation_script.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import subprocess
44
import fdsplotlib
5+
import matplotlib.pyplot as plt
56
import importlib
67
import runpy
78
importlib.reload(fdsplotlib) # use for development (while making changes to fdsplotlib.py)
@@ -12,6 +13,8 @@
1213
def safe_run(script_path):
1314
try:
1415
runpy.run_path(script_path, run_name="__main__")
16+
plt.clf() # Clear the current figure (if any)
17+
plt.close('all') # Close all open figure windows
1518
except Exception as exc:
1619
print(f"Error in {script_path}: {exc}")
1720

Utilities/Python/FDS_verification_script.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import subprocess
66
import fdsplotlib
7+
import matplotlib.pyplot as plt
78
import runpy
89
import importlib
910
importlib.reload(fdsplotlib) # use for development (while making changes to fdsplotlib.py)
@@ -14,6 +15,8 @@
1415
def safe_run(script_path):
1516
try:
1617
runpy.run_path(script_path, run_name="__main__")
18+
plt.clf() # Clear the current figure (if any)
19+
plt.close('all') # Close all open figure windows
1720
except Exception as exc:
1821
print(f"Error in {script_path}: {exc}")
1922

Utilities/Python/fdsplotlib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,22 +2022,22 @@ def scatplot(saved_data, drange, **kwargs):
20222022

20232023
for _, row in Q.iterrows():
20242024
plt.close('all')
2025-
plt.figure().clear()
2025+
plt.clf()
20262026

20272027
Scatter_Plot_Title = row["Scatter_Plot_Title"]
20282028
Plot_Filename = row["Plot_Filename"]
20292029
Plot_Min = float(row["Plot_Min"])
20302030
Plot_Max = float(row["Plot_Max"])
20312031
Plot_Type = str(row["Plot_Type"]).strip().lower()
20322032

2033-
# --- MATLAB parity: Sigma_E only required for Validation ---
2033+
# --- Sigma_E only required for Validation ---
20342034
if Stats_Output.lower() == "validation":
20352035
Sigma_E_input = float(row["Sigma_E"]) if "Sigma_E" in row and not pd.isna(row["Sigma_E"]) else 0.0
20362036
else:
20372037
Sigma_E_input = 0.0
20382038

2039-
#if verbose:
2040-
# print(f"[scatplot] Processing {Scatter_Plot_Title}")
2039+
if verbose:
2040+
print(f"[scatplot] Processing {Scatter_Plot_Title}")
20412041

20422042
# Match dataplot entries
20432043
match_idx = [i for i, q in enumerate(Save_Quantity)
@@ -2276,7 +2276,7 @@ def _label_at(k, labels):
22762276
os.makedirs(os.path.dirname(pdf_path), exist_ok=True)
22772277
fig.savefig(pdf_path)
22782278
plt.close(fig)
2279-
plt.figure().clear()
2279+
plt.clf()
22802280

22812281
# --- Collect statistics for CSV/TeX ---
22822282
group_labels = []
@@ -2608,7 +2608,7 @@ def statistics_histogram(Measured_Values, Predicted_Values,
26082608
plt.tight_layout()
26092609
fig.savefig(outpath)
26102610
plt.close(fig)
2611-
plt.figure().clear()
2611+
plt.clf()
26122612

26132613
return f"{os.path.basename(Plot_Filename)}_Histogram"
26142614

0 commit comments

Comments
 (0)