plot_distrib fails
Beriefing opened this issue · comments
When I run plot.plot_distrib(rr)
, where rr
is a float list or a numpy array, I get the following error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\berief\Python\Python37\lib\site-packages\hrvanalysis\plot.py", line 78, in plot_distrib
plt.hist(nn_intervals, bins=range(min_nn_i - 10, max_nn_i + 10, bin_length))
TypeError: 'float' object cannot be interpreted as an integer
Possible fix:
Just cast max_nn_i
and max_nn_i
to int
or use np.arange
.
Hi,
Thanks for raising this issue :-) Yep I will try to do that soon.
It is actually due to the fact that the method expects a list of int as input.
Regards,
Robin
For those still waiting, you can fix it by simply casting the max and min values to int's (as range expects int values not floats). By doing something like:
def plot_distrib(nn_intervals, bin_length: int = 8):
"""
Function plotting histogram distribution of the NN Intervals. Useful for geometrical features.
Arguments
---------
nn_intervals : list
list of Normal to Normal Interval.
bin_length : int
size of the bin for histogram in ms, by default = 8.
"""
max_nn_i = max(nn_intervals)
min_nn_i = min(nn_intervals)
style.use("seaborn-darkgrid")
plt.figure(figsize=(12, 8))
plt.title("Distribution of Rr Intervals", fontsize=20)
plt.xlabel("Time (s)", fontsize=15)
plt.ylabel("Number of Rr Interval per bin", fontsize=15)
#Range expects an integer rather than a float
plt.hist(nn_intervals, bins=range(int(min_nn_i) - 10, int(max_nn_i) + 10, bin_length), rwidth=0.8)
plt.show()