Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seperate model summary plotting and pdf saving #756

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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