Skip to content

Commit f4d6702

Browse files
committed
enh - make plotting functions return Figures and manage matplotlib more flexibly
- let user have control on the figure (add custom titles, axes) - figures now allow the user to add them in subplots - give user flexibility to choose if they want the figure to be shown (show_figure=True or False) - fix plt.tight_layout() bug
1 parent 335a0d6 commit f4d6702

2 files changed

Lines changed: 310 additions & 113 deletions

File tree

pcntoolkit/normative_model.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import numpy as np
1515
import scipy.stats as stats
1616
import xarray as xr
17+
import matplotlib.pyplot as plt
1718

1819
from pcntoolkit.dataio.norm_data import NormData
1920
from pcntoolkit.math_functions.scaler import Scaler
@@ -162,12 +163,27 @@ def predict(self, data: NormData) -> NormData:
162163
data.save_results(resultsdir)
163164
if self.saveplots:
164165
plotdir = os.path.join(self.save_dir, "plots")
165-
plot_qq(data, plot_id_line=True, save_dir=plotdir)
166-
plot_centiles(
166+
167+
# QQ plots
168+
for fig in plot_qq(
169+
data,
170+
plot_id_line=True,
171+
save_dir=plotdir,
172+
show_figure=False
173+
):
174+
# Close all the figures after saving it to disk
175+
plt.close(fig)
176+
177+
# Centiles plots
178+
for fig in plot_centiles(
167179
self,
168180
data,
169181
save_dir=plotdir,
170-
)
182+
show_figure=False,
183+
):
184+
# Close all the figures after saving it to disk
185+
plt.close(fig)
186+
171187
return data
172188

173189
def fit_predict(self, fit_data: NormData, predict_data: NormData) -> NormData:

0 commit comments

Comments
 (0)