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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 33 additions & 28 deletions petab/visualize/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@

__all__ = ["Plotter", "MPLPlotter", "SeabornPlotter"]

#: Line style for the measurement data in line plots
measurement_line_style = "-."
#: Marker style for the measurement data in line plots
measurement_marker = "x"
#: Line style for the simulation data in line plots
simulation_line_style = "-"
#: Marker style for the simulation data in line plots
simulation_marker = "o"


class Plotter(ABC):
"""
Expand Down Expand Up @@ -78,7 +87,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 @@ -125,12 +134,7 @@ def generate_lineplot(
)
# sorts according to ascending order of conditions
cond, replicates = zip(
*sorted(
zip(
measurements_to_plot.conditions,
replicates
)
)
*sorted(zip(measurements_to_plot.conditions, replicates))
)
replicates = np.stack(replicates)

Expand All @@ -141,8 +145,8 @@ def generate_lineplot(
p = ax.plot(
cond,
replicates[:, 0],
linestyle="-.",
marker="x",
linestyle=measurement_line_style,
marker=measurement_marker,
markersize=10,
label=label_base,
)
Expand All @@ -151,8 +155,8 @@ def generate_lineplot(
ax.plot(
cond,
replicates[:, 1:],
linestyle="-.",
marker="x",
linestyle=measurement_line_style,
marker=measurement_marker,
markersize=10,
color=p[0].get_color(),
)
Expand Down Expand Up @@ -182,8 +186,8 @@ def generate_lineplot(
scond,
smean,
snoise,
linestyle="-.",
marker=".",
linestyle=measurement_line_style,
marker=measurement_marker,
label=label_base,
)

Expand Down Expand Up @@ -234,8 +238,8 @@ def generate_lineplot(
p = ax.plot(
xs,
ys,
linestyle="-",
marker="o",
linestyle=simulation_line_style,
marker=simulation_marker,
markevery=every,
label=label_base + " simulation",
color=simu_color,
Expand Down Expand Up @@ -634,8 +638,8 @@ def _line_plot_at_t_inf(
p = ax_inf.plot(
timepoints_inf,
[replicates[0]] * 3,
linestyle="-.",
marker="x",
linestyle=measurement_line_style,
marker=measurement_marker,
markersize=10,
markevery=[1],
label=label_base + " simulation",
Expand All @@ -646,8 +650,8 @@ def _line_plot_at_t_inf(
ax_inf.plot(
timepoints_inf,
[replicates[1:]] * 3,
linestyle="-.",
marker="x",
linestyle=simulation_line_style,
marker=simulation_marker,
markersize=10,
markevery=[1],
color=p[0].get_color(),
Expand All @@ -659,15 +663,16 @@ def _line_plot_at_t_inf(
measurements_data_to_plot_inf["mean"],
measurements_data_to_plot_inf["mean"],
],
linestyle="-.",
linestyle=measurement_line_style,
marker=measurement_marker,
color=color,
)
ax_inf.errorbar(
t_inf,
measurements_data_to_plot_inf["mean"],
measurements_data_to_plot_inf[noise_col],
linestyle="-.",
marker=".",
linestyle=measurement_line_style,
marker=measurement_marker,
label=label_base + " simulation",
color=p[0].get_color(),
)
Expand All @@ -693,8 +698,8 @@ def _line_plot_at_t_inf(
p = ax_inf.plot(
timepoints_inf,
[replicates[0]] * 3,
linestyle="-",
marker="o",
linestyle=simulation_line_style,
marker=simulation_marker,
markevery=[1],
label=label_base,
color=color,
Expand All @@ -704,17 +709,17 @@ def _line_plot_at_t_inf(
ax_inf.plot(
timepoints_inf,
[replicates[1:]] * 3,
linestyle="-",
marker="o",
linestyle=simulation_line_style,
marker=simulation_marker,
markevery=[1],
color=p[0].get_color(),
)
else:
ax_inf.plot(
timepoints_inf,
[simulations_data_to_plot_inf["mean"]] * 3,
linestyle="-",
marker="o",
linestyle=simulation_line_style,
marker=simulation_marker,
markevery=[1],
color=color,
)
Expand Down