Skip to content

Commit 6a55afc

Browse files
plakrisenkodweindl
andauthored
fix goodness_of_fit plot and add color parameter (#402)
* fix goodness_of_fit plot and add color parameter --------- Co-authored-by: Daniel Weindl <[email protected]>
1 parent 636404d commit 6a55afc

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

petab/v1/measurements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def assert_overrides_match_parameter_count(
289289
)
290290
}
291291
if NOISE_FORMULA in observable_df.columns
292-
else {obs_id: 0 for obs_id in observable_df.index.values}
292+
else dict.fromkeys(observable_df.index.values, 0)
293293
)
294294

295295
for _, row in measurement_df.iterrows():

petab/v1/visualize/plot_residuals.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def plot_goodness_of_fit(
134134
petab_problem: Problem,
135135
simulations_df: str | Path | pd.DataFrame,
136136
size: tuple = (10, 7),
137+
color=None,
137138
ax: plt.Axes | None = None,
138139
) -> matplotlib.axes.Axes:
139140
"""
@@ -148,6 +149,9 @@ def plot_goodness_of_fit(
148149
output data file.
149150
size:
150151
Figure size.
152+
color:
153+
The marker colors, matches the `c` parameter of
154+
`matplotlib.pyplot.scatter`.
151155
ax:
152156
Axis object.
153157
@@ -171,8 +175,8 @@ def plot_goodness_of_fit(
171175
parameter_dfs=petab_problem.parameter_df,
172176
)[0]
173177
slope, intercept, r_value, p_value, std_err = stats.linregress(
174-
petab_problem.measurement_df["measurement"],
175178
simulations_df["simulation"],
179+
petab_problem.measurement_df["measurement"],
176180
) # x, y
177181

178182
if ax is None:
@@ -182,6 +186,7 @@ def plot_goodness_of_fit(
182186
ax.scatter(
183187
petab_problem.measurement_df["measurement"],
184188
simulations_df["simulation"],
189+
c=color,
185190
)
186191

187192
ax.axis("square")

tests/v1/test_visualization.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
import petab
1010
from petab.C import *
11-
from petab.visualize import (
11+
from petab.v1.visualize import (
1212
plot_goodness_of_fit,
1313
plot_residuals_vs_simulation,
1414
plot_with_vis_spec,
1515
plot_without_vis_spec,
1616
)
17-
from petab.visualize.lint import validate_visualization_df
18-
from petab.visualize.plotting import VisSpecParser
17+
from petab.v1.visualize.lint import validate_visualization_df
18+
from petab.v1.visualize.plotting import VisSpecParser
1919

2020
# Avoid errors when plotting without X server
2121
plt.switch_backend("agg")

0 commit comments

Comments
 (0)