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

Residuals plot #187

Merged
merged 17 commits into from
Jan 31, 2023
Merged
Prev Previous commit
Next Next commit
add ax argument
  • Loading branch information
plakrisenko committed Jan 17, 2023
commit f7d4db1aa14a0732d83c504dc781b2aa83c1f3cb
17 changes: 10 additions & 7 deletions petab/visualize/plot_residuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Functions for plotting residuals.
"""
from pathlib import Path
from typing import Tuple, Union
from typing import Optional, Tuple, Union

import matplotlib
import matplotlib.pyplot as plt
Expand All @@ -14,10 +14,12 @@
from ..C import *


def plot_residuals(petab_problem: problem.Problem,
simulations_df: Union[str, pd.DataFrame],
size: Tuple = (10, 7)
) -> matplotlib.axes.Axes:
def plot_residuals(
petab_problem: problem.Problem,
simulations_df: Union[str, pd.DataFrame],
size: Tuple = (10, 7),
ax: Optional[plt.Axes] = None
) -> matplotlib.axes.Axes:
"""
Plot residuals versus simulation values for measurements with normal noise
assumption.
Expand Down Expand Up @@ -57,8 +59,9 @@ def plot_residuals(petab_problem: problem.Problem,
raise ValueError("Residuals plot is only applicable for normal "
"additive noise assumption")

fig, ax = plt.subplots(figsize=size)
fig.set_layout_engine("tight")
if ax is None:
fig, ax = plt.subplots(figsize=size)
fig.set_layout_engine("tight")

residual_df = calculate.calculate_residuals(
measurement_dfs=petab_problem.measurement_df,
Expand Down