diff --git a/src/wela/plotting.py b/src/wela/plotting.py index 1cc02102c4c65994ddcaae801a7a6354efebf182..778c928f06e169ed4e2674e6978718a0a62dbead 100644 --- a/src/wela/plotting.py +++ b/src/wela/plotting.py @@ -609,7 +609,7 @@ def bud_to_bud_plot( dl, colour="b", group=None, - nbins=None, + no_t_values=None, no_future_buddings=1, return_signal=False, df=None, @@ -637,9 +637,9 @@ def bud_to_bud_plot( Colour of lines. group: str, optional The name of the group to plot. - nbins: int, optional - The number of time bins to partition the interval between the - first and the second budding event. + no_t_values: int, optional + The number of time points into which to partition the interval between + budding events. no_future_buddings: int, optional The number of future budding events to include. Default is 1. return_signal: boolean, optional @@ -664,10 +664,10 @@ def bud_to_bud_plot( >>> bud_to_bud_plot(4, "flavin", dl, group="fy4", filter_func=butterworth_filter) """ if df is None: - t, signal_data = dl.get_time_series(signal, group=group) + _, signal_data = dl.get_time_series(signal, group=group) t, buddings = dl.get_time_series("buddings", group=group) else: - t, signal_data = dl.get_time_series(signal, group=group, df=df) + _, signal_data = dl.get_time_series(signal, group=group, df=df) t, buddings = dl.get_time_series("buddings", group=group, df=df) if filter_func is not None: signal_data = filter_func(signal_data) @@ -684,11 +684,14 @@ def bud_to_bud_plot( no_future_buddings_index=no_future_buddings - 1, ) if local_times: - # find bins for normalised time, between 0 and no_future_buddings - nbins = int(np.median([len(local_time) for local_time in local_times])) - ntbins = np.linspace(0, no_future_buddings, nbins) + # find values for normalised time between 0 and no_future_buddings + if no_t_values is None: + no_t_values = int( + np.median([len(local_time) for local_time in local_times]) + ) + t_values = np.linspace(0, no_future_buddings, no_t_values) # interpolate each local signal to make a new signal - new_signal = np.nan * np.ones((len(local_signals), nbins)) + new_signal = np.nan * np.ones((len(local_signals), no_t_values)) for i in range(len(local_signals)): s = local_signals[i] # normalise time between 0 and no_future_buddings @@ -696,7 +699,7 @@ def bud_to_bud_plot( nt = nt / nt[-1] * no_future_buddings # interpolate into the bins new_signal[i, :] = np.interp( - ntbins, + t_values, nt[~np.isnan(s)], s[~np.isnan(s)], left=np.nan, @@ -705,10 +708,10 @@ def bud_to_bud_plot( # plot median and percentiles if show_figure: plt.figure() - plt.plot(ntbins, np.nanmedian(new_signal, axis=0), f"{colour}.-") + plt.plot(t_values, np.nanmedian(new_signal, axis=0), f"{colour}.-") for lower, upper in zip([45, 40, 35], [55, 60, 65]): plt.fill_between( - ntbins, + t_values, np.nanpercentile(new_signal, lower, axis=0), np.nanpercentile(new_signal, upper, axis=0), alpha=0.06,