From 38f5a8178325be578518d176ae13b3f2cd25446b Mon Sep 17 00:00:00 2001 From: Polina Lakrisenko Date: Mon, 7 Jul 2025 20:57:55 +0200 Subject: [PATCH 1/4] fix goodness_of_fit plot and add color parameter --- petab/v1/visualize/plot_residuals.py | 6 +++++- tests/v1/test_visualization.py | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/petab/v1/visualize/plot_residuals.py b/petab/v1/visualize/plot_residuals.py index a45fcde3..e563a07f 100644 --- a/petab/v1/visualize/plot_residuals.py +++ b/petab/v1/visualize/plot_residuals.py @@ -134,6 +134,7 @@ def plot_goodness_of_fit( petab_problem: Problem, simulations_df: str | Path | pd.DataFrame, size: tuple = (10, 7), + color = None, ax: plt.Axes | None = None, ) -> matplotlib.axes.Axes: """ @@ -148,6 +149,8 @@ def plot_goodness_of_fit( output data file. size: Figure size. + color: + The marker colors, matches the `c` parameter of `matplotlib.pyplot.scatter`. ax: Axis object. @@ -171,8 +174,8 @@ def plot_goodness_of_fit( parameter_dfs=petab_problem.parameter_df, )[0] slope, intercept, r_value, p_value, std_err = stats.linregress( - petab_problem.measurement_df["measurement"], simulations_df["simulation"], + petab_problem.measurement_df["measurement"], ) # x, y if ax is None: @@ -182,6 +185,7 @@ def plot_goodness_of_fit( ax.scatter( petab_problem.measurement_df["measurement"], simulations_df["simulation"], + c=color, ) ax.axis("square") diff --git a/tests/v1/test_visualization.py b/tests/v1/test_visualization.py index 0edd4b78..3c5a3a65 100644 --- a/tests/v1/test_visualization.py +++ b/tests/v1/test_visualization.py @@ -8,14 +8,14 @@ import petab from petab.C import * -from petab.visualize import ( +from petab.v1.visualize import ( plot_goodness_of_fit, plot_residuals_vs_simulation, plot_with_vis_spec, plot_without_vis_spec, ) -from petab.visualize.lint import validate_visualization_df -from petab.visualize.plotting import VisSpecParser +from petab.v1.visualize.lint import validate_visualization_df +from petab.v1.visualize.plotting import VisSpecParser # Avoid errors when plotting without X server plt.switch_backend("agg") From 5de85581f0cbaf500f2df90bcf80223ed90546f9 Mon Sep 17 00:00:00 2001 From: Polina Lakrisenko Date: Mon, 7 Jul 2025 21:10:49 +0200 Subject: [PATCH 2/4] style --- petab/v1/visualize/plot_residuals.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/petab/v1/visualize/plot_residuals.py b/petab/v1/visualize/plot_residuals.py index e563a07f..ee0826d1 100644 --- a/petab/v1/visualize/plot_residuals.py +++ b/petab/v1/visualize/plot_residuals.py @@ -150,7 +150,8 @@ def plot_goodness_of_fit( size: Figure size. color: - The marker colors, matches the `c` parameter of `matplotlib.pyplot.scatter`. + The marker colors, matches the `c` parameter of + `matplotlib.pyplot.scatter`. ax: Axis object. From 5604a78b2143890f558e0ec02cd0421c5da1714f Mon Sep 17 00:00:00 2001 From: Polina Lakrisenko Date: Mon, 7 Jul 2025 21:27:58 +0200 Subject: [PATCH 3/4] style --- petab/v1/measurements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/petab/v1/measurements.py b/petab/v1/measurements.py index ec7a1069..8b23907b 100644 --- a/petab/v1/measurements.py +++ b/petab/v1/measurements.py @@ -289,7 +289,7 @@ def assert_overrides_match_parameter_count( ) } if NOISE_FORMULA in observable_df.columns - else {obs_id: 0 for obs_id in observable_df.index.values} + else dict.fromkeys(observable_df.index.values, 0) ) for _, row in measurement_df.iterrows(): From f48902e69c8b6e34b31c4e7692fa80fb3cb636ff Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 8 Jul 2025 11:51:31 +0200 Subject: [PATCH 4/4] ruff --- petab/v1/visualize/plot_residuals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/petab/v1/visualize/plot_residuals.py b/petab/v1/visualize/plot_residuals.py index ee0826d1..14a62f8a 100644 --- a/petab/v1/visualize/plot_residuals.py +++ b/petab/v1/visualize/plot_residuals.py @@ -134,7 +134,7 @@ def plot_goodness_of_fit( petab_problem: Problem, simulations_df: str | Path | pd.DataFrame, size: tuple = (10, 7), - color = None, + color=None, ax: plt.Axes | None = None, ) -> matplotlib.axes.Axes: """