title: Plot a histogram such that the total height equals 1
body: <p>This is a follow-up question to this <a href="https://stackoverflow.com/a/16399202/7758804">answer</a>. I'm trying to plot normed histogram, but instead of getting 1 as maximum value on y axis, I'm getting different numbers.</p>
  <p>For array k=(1,4,3,1)</p>
  <pre><code> import numpy as np
  
   def plotGraph():
     
      import matplotlib.pyplot as plt
      
      k=(1,4,3,1)
  
      plt.hist(k, normed=1)
  
      from numpy import *
      plt.xticks( arange(10) ) # 10 ticks on x axis
  
      plt.show()  
      
  plotGraph()
  </code></pre>
  <p>I get this histogram, that doesn't look like normed.</p>
  <p><img src="https://i.stack.imgur.com/t99xD.png" alt="enter image description here" /></p>
  <p>For a different array k=(3,3,3,3)</p>
  <pre><code> import numpy as np
  
   def plotGraph():
     
      import matplotlib.pyplot as plt
      
      k=(3,3,3,3)
  
      plt.hist(k, normed=1)
  
      from numpy import *
      plt.xticks( arange(10) ) # 10 ticks on x axis
  
      plt.show()  
      
  plotGraph()
  </code></pre>
  <p>I get this histogram with max y-value is 10.</p>
  <p><img src="https://i.stack.imgur.com/8Ag3d.png" alt="enter image description here" /></p>
  <p>For different k I get different max value of y even though normed=1 or normed=True.</p>
  <p>Why the normalization (if it works) changes based on the data and how can I make maximum value of y equals to 1?</p>
  <p><strong>UPDATE:</strong></p>
  <p>I am trying to implement <a href="https://stackoverflow.com/users/1542814/carsten-konig">Carsten König</a> answer from <a href="https://stackoverflow.com/questions/3866520/plotting-histograms-whose-bar-heights-sum-to-1-in-matplotlib">plotting histograms whose bar heights sum to 1 in matplotlib</a> and getting very weird result:</p>
  <pre><code>import numpy as np
  
  def plotGraph():
  
      import matplotlib.pyplot as plt
  
      k=(1,4,3,1)
  
      weights = np.ones_like(k)/len(k)
      plt.hist(k, weights=weights)
  
      from numpy import *
      plt.xticks( arange(10) ) # 10 ticks on x axis
  
      plt.show()  
  
  plotGraph()
  </code></pre>
  <p>Result:</p>
  <p><img src="https://i.stack.imgur.com/FVmUu.png" alt="enter image description here" /></p>
  <p>What am I doing wrong?</p>