title: Gaps in matplotlib's histogram `hist`
body: <p>I am following an online course on Python.  This is the code, verbatim.  It conducts a Monte Carlo repetition of 100 random walks, 10 steps each.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  np.random.seed(123)
  final_tails = []
  for x in range(100) :
     tails = [0]
     for x in range(10) :
        coin = np.random.randint(0, 2)
        tails.append(tails[x] + coin)
     final_tails.append(tails[-1])
  plt.hist(final_tails, bins = 10)
  plt.show()
  </code></pre>
  
  <p>The course says that I should get the plot without gaps.  I get exactly the same bar heights, in exactly the same order, but with some odd spacing gaps between them.</p>
  
  <p>Can anyone corroborate this result or explain it?</p>
  
  <p><a href="https://i.stack.imgur.com/hqh3L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hqh3L.png" alt="enter image description here"></a><a href="https://i.stack.imgur.com/vgg7x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vgg7x.png" alt="enter image description here"></a></p>
  
  <p>I am using:</p>
  
  <ul>
  <li>Python 3.7.1 64-bit</li>
  <li>Windws 7 64-bit</li>
  <li>Spyder 3.3.2</li>
  </ul>
  
  <p>Thanks.</p>
  
  <p><strong>AFTERNOTE</strong></p>
  
  <p>I noticed that, unlike the course's abutted bars, my bin edges align with integers.  This is not good, as the data will be integers, but whether the integers fall into the left or right side of the bin edges should be consistent.  Hence, it doesn't seem to explain the gap.  It could mean, however, that the auto-generation of bin edges changed somewhere in the evolution of matplotlib.  I don't know what version the course uses.</p>
  
  <p><strong>P.S.</strong> The following indicates the problem is that the bin edges don't
  straddle all the integers in the data value range:</p>
  
  <pre><code>print( np.unique( np.array( final_tails ) ) )
  print( np.unique( final_tails ) ) # data values
  hist, bin_edges = np.histogram( final_tails )
  print(bin_edges) # bin edges
  print(hist) # bar heights
  </code></pre>
  
  <ul>
  <li><p>The data values are: [2 3 4 5 6 7 8 9]</p></li>
  <li><p>The bin edges are: [2.  2.7 3.4 4.1 4.8 5.5 6.2 6.9 7.6 8.3 9. ]</p></li>
  <li><p>The bar heights are: [ 2 10 23  0 21 27  0 10  6  1]</p></li>
  </ul>
  
  <p>I got the course's nice abutted bars using:</p>
  
  <pre><code>plt.hist( final_tails ,
     bins = np.arange( min( final_tails ) - 0.5 ,
                       max( final_tails ) + 1.5 , 1.0 ) ,
     edgecolor="k" )
  plt.show()
  </code></pre>
  
  <p>I have not posted this as the answer, as the credit goes to saibhaskar
  and ImportanceOfBeingErnest, who provided the details.</p>
  
  <p>But I do wonder whether this need to customize the bin edges is might
  be because the scheme for automatic bin edges has changed between the
  creation of the course material and now.</p>