2

I am plotting histograms and I found this on stack exchange which works great: histogram for discrete values

Here is the code posted there:

import matplotlib.pyplot as plt
import numpy as np

data = range(11)
data = np.array(data)

d = np.diff(np.unique(data)).min()
left_of_first_bin = data.min() - float(d)/2
right_of_last_bin = data.max() + float(d)/2
plt.hist(data, np.arange(left_of_first_bin, right_of_last_bin + d, d))
plt.show() 

I am using it with a case where d = 2.84e-5, the output of np.arrange() above is then 68704 in length. If I run this from python interpreter (python 3.5) on ubuntu 14.04 from an anaconda environment, the system hangs and I can not recover without ctrl-c which kills the interpreter. I am wondering if there is a limit on the size of bins in plt.hist() or if there is something inherently wrong with this approach. If a limitation, I would expect an error rather than a hang. The code works fine if d is not too small. The length of my data might be impacting this as well, it was 22289. I guess it could just be churning and I am not waiting long enough?

I searched for matplotlib.pyplot.hist limitations and other variations and could not find anything. The documentation from what I can tell does not mention a limit. Thank you.

Community
  • 1
  • 1
Zak Keirn
  • 807
  • 13
  • 22

1 Answers1

5

It looks like there is not a real hang. It just takes forever because the data is so large and the bin widths so small. I noted that with d=.001, it took about 30 seconds on my machine to render the plot. Sorry for the trouble, I thought I found a potential bug and as a newbie got excited.

Zak Keirn
  • 807
  • 13
  • 22