title: Python: Histogram return wrong values for counts (EDIT: more general with example)
body: <p>EDIT: Ive found a general example where it doesnt work either!
  I am trying to extract the data for a histogram, but different counts seem wrong. As an example code:</p>
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  data = np.random.rand(1000000)
  bins = np.arange(0,1,0.0001)
  a,b,c = plt.hist(data,bins)
  </code></pre>
  <p>This gives me <a href="https://i.stack.imgur.com/x1w50.png" rel="nofollow noreferrer">this rather messy</a> histogram, and i've saved the counts as a and the interval as b. Now, plotting a and b, I should expect the same histogram, right? But that's not what I get:</p>
  <pre><code>plt.scatter(b[0:len(b)-1],a,s=2)
  </code></pre>
  <p>which gives me <a href="https://i.stack.imgur.com/Y45Pe.png" rel="nofollow noreferrer">this</a>, which doesnt match at all! Furthurmore, when I try and find the maximum value of a, it gives me 144, which fits fine with the scatterplot, but not with the histogram function.</p>
  <p>If I count the numbers myself with the following code:</p>
  <pre><code>len(np.intersect1d(np.where(data&gt;=b[np.argmax(a)]),np.where(data&lt;b[np.argmax(a)+1])))
  </code></pre>
  <p>then it also gives me 144, in accordance with the values. So is the displayed histogram just wrong for some reason, and I should ignore it and just take the extracted data?</p>
  <p><strong>Old, unedited post:</strong></p>
  <p>For a physics course I am trying to bin my results in the following way:</p>
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  import scipy.stats as ss
  from scipy.optimize import curve_fit
  plt.rc(&quot;font&quot;, family=[&quot;Helvetica&quot;, &quot;Arial&quot;]) 
  plt.rc(&quot;axes&quot;, labelsize=18)
  plt.rc(&quot;xtick&quot;, labelsize=16, top=True, direction=&quot;in&quot;)
  plt.rc(&quot;ytick&quot;, labelsize=16, right=True, direction=&quot;in&quot;)
  plt.rc(&quot;axes&quot;, titlesize=22)
  plt.rc(&quot;legend&quot;, fontsize=16)
  
  data_Ra = np.loadtxt('Ra226_cal2_ch001.txt',skiprows=5)
  t_Ra = data_Ra[:,0]*10**-8 # time in seconds 
  channels_Ra = data_Ra[:,1]
  channels_Ra = channels_Ra[np.where(channels_Ra&gt;0)] # removing all the measurements at channel = 0
  intervalspace = 2 #The intervals in which we count
  bins=np.arange(0,4000,intervalspace)
  
  
  counts, intervals , stuff = plt.hist(channels_Ra,bins)
  plt.xlabel('Channels')
  plt.ylabel('Counts')
  plt.show()
  </code></pre>
  <p>Here, the <a href="https://i.stack.imgur.com/BCDCr.png" rel="nofollow noreferrer">histogram plot</a> looks totally fine, with a max near 13000 counts. But when I then use np.max(counts), I am given about 24000, and when I try and just plot the values it gives me with:</p>
  <pre><code>plt.scatter(intervals[0:len(intervals)-1]+intervalspace/2,counts,s=1)
  plt.xlabel('Channels')
  plt.ylabel('Counts')
  plt.title('Ra225')
  plt.show()
  </code></pre>
  <p>it looks like <a href="https://i.stack.imgur.com/2p1Fa.png" rel="nofollow noreferrer">this</a>, which is totally different, and I can't figure out why. I am expecting the scatterplot to resemble the histogram, and while the peaks are located at the same x-vales, the height do not match.</p>
  <p>This problem is in other large datasets as well.</p>
  <p>I dont think i'm allowed to drop the txt-file here? So im not sure how much more I can show, but any help will be appreciated!</p>