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

Vis: Make line plot markers configurable #254

Merged
merged 4 commits into from
Apr 16, 2024
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
54 changes: 28 additions & 26 deletions petab/visualize/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
__all__ = ["Plotter", "MPLPlotter", "SeabornPlotter"]


#: Line style (:class:`matplotlib.lines.Line2D` options) for the measurement
# data in line plots
measurement_line_kwargs = {
"linestyle": "-.",
"marker": "x",
"markersize": 10,
}
#: Line style (:class:`matplotlib.lines.Line2D` options) for the simulation
# data in line plots
simulation_line_kwargs = {
"linestyle": "-",
"marker": "o",
"markersize": 10,
}


class Plotter(ABC):
"""
Plotter abstract base class.
Expand Down Expand Up @@ -78,7 +94,7 @@ def generate_lineplot(
splitaxes_params: dict,
) -> Tuple[matplotlib.axes.Axes, matplotlib.axes.Axes]:
"""
Generate lineplot.
Generate line plot.

It is possible to plot only data or only simulation or both.

Expand Down Expand Up @@ -136,19 +152,15 @@ def generate_lineplot(
p = ax.plot(
cond,
replicates[:, 0],
linestyle="-.",
marker="x",
markersize=10,
label=label_base,
**measurement_line_kwargs,
)

# plot other replicates with the same color
ax.plot(
cond,
replicates[:, 1:],
linestyle="-.",
marker="x",
markersize=10,
**measurement_line_kwargs,
color=p[0].get_color(),
)

Expand Down Expand Up @@ -177,9 +189,8 @@ def generate_lineplot(
scond,
smean,
snoise,
linestyle="-.",
marker=".",
label=label_base,
**measurement_line_kwargs,
)

# simulations should have the same colors if both measurements
Expand Down Expand Up @@ -229,11 +240,10 @@ def generate_lineplot(
p = ax.plot(
xs,
ys,
linestyle="-",
marker="o",
markevery=every,
label=label_base + " simulation",
color=simu_color,
**simulation_line_kwargs,
)
# lines at t=inf should have the same colors also in case
# only simulations are plotted
Expand Down Expand Up @@ -628,23 +638,19 @@ def _line_plot_at_t_inf(
p = ax_inf.plot(
timepoints_inf,
[replicates[0]] * 3,
linestyle="-.",
marker="x",
markersize=10,
markevery=[1],
label=label_base + " simulation",
color=color,
**measurement_line_kwargs,
)

# plot other replicates with the same color
ax_inf.plot(
timepoints_inf,
[replicates[1:]] * 3,
linestyle="-.",
marker="x",
markersize=10,
markevery=[1],
color=p[0].get_color(),
**measurement_line_kwargs,
)
else:
p = ax_inf.plot(
Expand All @@ -653,17 +659,16 @@ def _line_plot_at_t_inf(
measurements_data_to_plot_inf["mean"],
measurements_data_to_plot_inf["mean"],
],
linestyle="-.",
color=color,
**measurement_line_kwargs,
)
ax_inf.errorbar(
t_inf,
measurements_data_to_plot_inf["mean"],
measurements_data_to_plot_inf[noise_col],
linestyle="-.",
marker=".",
label=label_base + " simulation",
color=p[0].get_color(),
**measurement_line_kwargs,
)

if color is None:
Expand All @@ -687,30 +692,27 @@ def _line_plot_at_t_inf(
p = ax_inf.plot(
timepoints_inf,
[replicates[0]] * 3,
linestyle="-",
marker="o",
markevery=[1],
label=label_base,
color=color,
**simulation_line_kwargs,
)

# plot other replicates with the same color
ax_inf.plot(
timepoints_inf,
[replicates[1:]] * 3,
linestyle="-",
marker="o",
markevery=[1],
color=p[0].get_color(),
**simulation_line_kwargs,
)
else:
ax_inf.plot(
timepoints_inf,
[simulations_data_to_plot_inf["mean"]] * 3,
linestyle="-",
marker="o",
markevery=[1],
color=color,
**simulation_line_kwargs,
)

ax.set_xlim(right=ax_finite_right_limit)
Expand Down
Loading