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

plot_distrib fails #21

Open
Beriefing opened this issue Feb 4, 2020 · 2 comments
Open

plot_distrib fails #21

Beriefing opened this issue Feb 4, 2020 · 2 comments

Comments

@Beriefing
Copy link

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.

@robinchampseix
Copy link
Collaborator

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

@ghost
Copy link

ghost commented Aug 17, 2022

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants