Skip to content

Commit

Permalink
Seperate model summary plotting and pdf saving (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonk committed May 15, 2024
1 parent ab06d0e commit 526da56
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions pastas/plotting/modelplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,16 +1022,14 @@ def series(
return axes

@model_tmin_tmax
def summary_pdf(
def summary(
self,
tmin: Optional[TimestampType] = None,
tmax: Optional[TimestampType] = None,
fname: Optional[str] = None,
dpi: int = 150,
results_kwargs: Optional[dict] = None,
diagnostics_kwargs: Optional[dict] = None,
) -> Figure:
"""Create a PDF file (A4) with the results and diagnostics plot.
"""Create a plot with the results and diagnostics plot.
Parameters
----------
Expand All @@ -1050,17 +1048,13 @@ def summary_pdf(
-------
fig: matplotlib.pyplot.Figure instance
"""
if fname is None:
fname = "{}.pdf".format(self.ml.name)

if results_kwargs is None:
results_kwargs = {}

if diagnostics_kwargs is None:
diagnostics_kwargs = {}

pdf = PdfPages(fname)

fig = plt.figure(figsize=(8.27, 11.69), dpi=50)

fig1, fig2 = fig.subfigures(2, 1, height_ratios=[1.25, 1.0])
Expand All @@ -1073,6 +1067,45 @@ def summary_pdf(
fig2.suptitle("Model Diagnostics", fontweight="bold")

plt.subplots_adjust(left=0.1, top=0.9, right=0.95, bottom=0.1)
return fig

@model_tmin_tmax
def summary_pdf(
self,
tmin: Optional[TimestampType] = None,
tmax: Optional[TimestampType] = None,
results_kwargs: Optional[dict] = None,
diagnostics_kwargs: Optional[dict] = None,
fname: Optional[str] = None,
dpi: int = 150,
) -> Figure:
"""Create a PDF file (A4) with the results and diagnostics plot.
Parameters
----------
tmin: str or pd.Timestamp, optional
tmax: str or pd.Timestamp, optional
results_kwargs: dict, optional
dictionary passed on to ml.plots.results method.
diagnostics_kwargs: dict, optional
dictionary passed on to ml.plots.diagnostics method.
fname: str, optional
string with the file name / path to store the PDF file.
dpi: int, optional
dpi to save the figure with.
Returns
-------
fig: matplotlib.pyplot.Figure instance
"""
fname = "{}.pdf".format(self.ml.name) if fname is None else fname
pdf = PdfPages(fname)
fig = self.summary(
tmin=tmin,
tmax=tmax,
results_kwargs=results_kwargs,
diagnostics_kwargs=diagnostics_kwargs,
)
pdf.savefig(fig, orientation="portrait", dpi=dpi)
pdf.close()
return fig
Expand Down

0 comments on commit 526da56

Please sign in to comment.