Skip to content
Snippets Groups Projects
Commit 043caf5a authored by Arin Wongprommoon's avatar Arin Wongprommoon
Browse files

refactor(postproc): make birth event legend label an argument

WHY IS THIS CHANGE NEEDED?:
- when using single_birth_plot routine, user can change the label in
  the legend that indicates birth events

HOW DOES THE CHANGE SOLVE THE PROBLEM?:
- remove hard-coding of the 'birth event' label by making it an argument
  with the default of 'birth event'.
- this preserves backwards compatibility as i'm creating a new argument
  and the existing argument names are the same

WHAT SIDE EFFECTS DOES THIS CHANGE HAVE?:
- backwards compatibility: existing uses of this routine in scripts will
  produce 'budding event' in plots rather than 'birth event'; if a user
  wants to use 'birth event', they can simply define the argument
  birth_label='birth event'.

EVIDENCE THAT COMMIT WORKS:
- works with a random time series and a binary mask-like numpy array,
  and i can change the legend label

REFERENCES:
- issue #36
parent b206c48a
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ class _SingleBirthPlotter(_SinglePlotter): ...@@ -21,6 +21,7 @@ class _SingleBirthPlotter(_SinglePlotter):
birth_linestyle, birth_linestyle,
xlabel, xlabel,
ylabel, ylabel,
birth_label,
plot_title, plot_title,
): ):
# Define attributes from arguments # Define attributes from arguments
...@@ -39,6 +40,7 @@ class _SingleBirthPlotter(_SinglePlotter): ...@@ -39,6 +40,7 @@ class _SingleBirthPlotter(_SinglePlotter):
self.birth_mask = birth_mask self.birth_mask = birth_mask
self.birth_color = birth_color self.birth_color = birth_color
self.birth_linestyle = birth_linestyle self.birth_linestyle = birth_linestyle
self.birth_label = birth_label
def plot(self, ax): def plot(self, ax):
"""Draw the line plots on the provided Axes.""" """Draw the line plots on the provided Axes."""
...@@ -47,7 +49,7 @@ class _SingleBirthPlotter(_SinglePlotter): ...@@ -47,7 +49,7 @@ class _SingleBirthPlotter(_SinglePlotter):
birth_mask_bool = self.birth_mask.astype(bool) birth_mask_bool = self.birth_mask.astype(bool)
for occurence, birth_time in enumerate(trace_time[birth_mask_bool]): for occurence, birth_time in enumerate(trace_time[birth_mask_bool]):
if occurence == 0: if occurence == 0:
label = "birth event" label = self.birth_label
else: else:
label = None label = None
ax.axvline( ax.axvline(
...@@ -71,6 +73,7 @@ def single_birth_plot( ...@@ -71,6 +73,7 @@ def single_birth_plot(
birth_linestyle="--", birth_linestyle="--",
xlabel="Time (min)", xlabel="Time (min)",
ylabel="Normalised flavin fluorescence (AU)", ylabel="Normalised flavin fluorescence (AU)",
birth_label="budding event",
plot_title="", plot_title="",
ax=None, ax=None,
): ):
...@@ -101,6 +104,8 @@ def single_birth_plot( ...@@ -101,6 +104,8 @@ def single_birth_plot(
x axis label. x axis label.
ylabel : string ylabel : string
y axis label. y axis label.
birth_label : string
label for budding event, 'budding event' by default.
plot_title : string plot_title : string
Plot title. Plot title.
ax : matplotlib Axes ax : matplotlib Axes
...@@ -128,6 +133,7 @@ def single_birth_plot( ...@@ -128,6 +133,7 @@ def single_birth_plot(
birth_linestyle, birth_linestyle,
xlabel, xlabel,
ylabel, ylabel,
birth_label,
plot_title, plot_title,
) )
if ax is None: if ax is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment