in src/lookoutequipment/plot.py [0:0]
def compute_bin_edges(signals, num_bins=10):
"""
Computes aligned bin edges for all signals passed in argument
Parameters:
signals (array_like):
An array holding the elements we want to compute histogram bins
for. Could be two pandas.Series, numpy arrays, lists...
num_bins (integer):
Number of bins to compute (defaults to 10)
Returns:
list: a list of (num_bins + 1) edges that can be used to plot a
histogram
"""
# Checks if the argument is a nested type or a numeric one:
if isinstance(signals[0], (int, float)):
all_signals_min = np.min(signals)
all_signals_max = np.max(signals)
# For nested type (list of pandas.Series, list of lists...), we
# need to compute the min and max of each component of the list:
else:
all_signals_max = None
all_signals_min = None
for s in signals:
signal_max = np.max(s)
if (all_signals_max is not None) and (signal_max > all_signals_max):
all_signals_max = signal_max
elif all_signals_max is None:
all_signals_max = signal_max
signal_min = np.min(s)
if (all_signals_min is not None) and (signal_min < all_signals_min):
all_signals_min = signal_min
elif all_signals_min is None:
all_signals_min = signal_min
# Now we can compute the bin width and their edges:
bin_width = (all_signals_max - all_signals_min)/num_bins
bins = np.arange(
all_signals_min,
all_signals_max + bin_width,
bin_width
)
return bins