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

Optionally include measurements in plot_observable_trajectories #2381

Merged
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
46 changes: 36 additions & 10 deletions python/sdist/amici/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seaborn as sns
from matplotlib.axes import Axes

import amici
from . import Model, ReturnDataView
from .numpy import StrOrExpr, evaluate

Expand Down Expand Up @@ -66,10 +67,11 @@

for ix, label in zip(state_indices, labels):
ax.plot(rdata["t"], rdata["x"][:, ix], marker=marker, label=label)
ax.set_xlabel("$t$")
ax.set_ylabel("$x(t)$")
ax.legend()
ax.set_title("State trajectories")

ax.set_xlabel("$t$")
ax.set_ylabel("$x(t)$")
ax.legend()
ax.set_title("State trajectories")

Check warning on line 74 in python/sdist/amici/plotting.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/plotting.py#L71-L74

Added lines #L71 - L74 were not covered by tests


def plot_observable_trajectories(
Expand All @@ -79,6 +81,7 @@
model: Model = None,
prefer_names: bool = True,
marker=None,
edata: Union[amici.ExpData, amici.ExpDataView] = None,
) -> None:
"""
Plot observable trajectories.
Expand All @@ -97,8 +100,12 @@
:param marker:
Point marker for plotting (see
`matplotlib documentation <https://matplotlib.org/stable/api/markers_api.html>`_).

:param edata:
Experimental data to be plotted (no event observables yet).
"""
if isinstance(edata, amici.amici.ExpData):
edata = amici.ExpDataView(edata)

Check warning on line 107 in python/sdist/amici/plotting.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/plotting.py#L106-L107

Added lines #L106 - L107 were not covered by tests

if not ax:
fig, ax = plt.subplots()
if not observable_indices:
Expand All @@ -125,11 +132,30 @@
labels = np.asarray(rdata.ptr.observable_ids)[list(observable_indices)]

for iy, label in zip(observable_indices, labels):
ax.plot(rdata["t"], rdata["y"][:, iy], marker=marker, label=label)
ax.set_xlabel("$t$")
ax.set_ylabel("$y(t)$")
ax.legend()
ax.set_title("Observable trajectories")
(l,) = ax.plot(

Check warning on line 135 in python/sdist/amici/plotting.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/plotting.py#L135

Added line #L135 was not covered by tests
rdata["t"], rdata["y"][:, iy], marker=marker, label=label
)

if edata is not None:
ax.plot(

Check warning on line 140 in python/sdist/amici/plotting.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/plotting.py#L139-L140

Added lines #L139 - L140 were not covered by tests
edata.ts,
edata.observedData[:, iy],
"x",
label=f"exp. {label}",
color=l.get_color(),
)
ax.errorbar(

Check warning on line 147 in python/sdist/amici/plotting.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/plotting.py#L147

Added line #L147 was not covered by tests
edata.ts,
edata.observedData[:, iy],
yerr=rdata.sigmay[:, iy],
fmt="none",
color=l.get_color(),
)

ax.set_xlabel("$t$")
ax.set_ylabel("$y(t)$")
ax.set_title("Observable trajectories")
ax.legend()

Check warning on line 158 in python/sdist/amici/plotting.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/plotting.py#L155-L158

Added lines #L155 - L158 were not covered by tests


def plot_jacobian(rdata: ReturnDataView):
Expand Down
Loading