0

I have a list of real numbers type float64 which I use them to plot their histogram. When I read my data file, I use this function:

def read1col(filename):
    data = []
    for line in open(filename,'r'):
        for word in line.split():
            data.append(word)

    data = np.asarray(data, dtype=np.longdouble)
    return data

If I use the function plt.hist(data, bins=100), matplotlib returns me the error:

The first argument of bincount must be non-negative

However, I want to say that it is an obscure error for the following reason: I have 60,000 numbers in the file to do the histogram. If I do plt.hist(data[:1000], bins=100) I obtain the histogram without problem. If I include more elements, then the error is raised up.

I use anaconda, also I just downloaded and re-installed it the past week.

user2820579
  • 3,261
  • 7
  • 30
  • 45
  • I guess this is an error produced in numpy, and has nothing to do with matplotlib. Can you check, what happens if you call `numpy.histogram(data, bins=100)` or any slice of it? In that case change the tag and title from *matplotlib* to *numpy* (such that the question will be seen by the right people. Can you provide more information? Does any other slice of 1000 points have that problem? Is this due to a specific value in the data? Can you provide the complete error, and your numpy version? – ImportanceOfBeingErnest Nov 09 '16 at 23:18
  • 2
    After reading [this](http://stackoverflow.com/questions/37119818/numpy-histogram-fails-after-updating-anaconda) you may just have a couple of `inf` or `nan` in your data. In this case [removing the nans and infs](http://stackoverflow.com/questions/11620914/removing-nan-values-from-an-array) may help. – ImportanceOfBeingErnest Nov 09 '16 at 23:34
  • Yes, I also saw that `nan` of `inf` rise such type of errors, but in my case any value is like those, so this is not the problem. – user2820579 Nov 10 '16 at 22:07
  • What do you mean by "any value is like those"? Are all values nan? In that case you will not be able to compute a histogram of it. You might still look at the points my first comment in order to find the problem. – ImportanceOfBeingErnest Nov 11 '16 at 08:25
  • No values that are nan or inf. I think my error could be reproduced if one just generates perhaps a `10,000` list of random numbers and then read it with the `dtype=np.longdouble`, and then try to do the histogram of such numbers. My numpy version is `1.11.1`. – user2820579 Nov 11 '16 at 18:20
  • Do you think it can be reproduced or did you try it. It's actually a good idea, so do that and report back if the problem persists. Also, I may again remind you of the questions I asked in my first comment, just in case you are still interested in finding a solution. – ImportanceOfBeingErnest Nov 11 '16 at 20:55

0 Answers0