title: How to make matplotlib/pandas bar chart look like hist chart?
body: <h1>Plotting Differences between <code>bar</code> and <code>hist</code></h1>
  
  <p>Given some data in a <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html#pandas-series" rel="noreferrer"><code>pandas.Series</code></a> , <code>rv</code>, there is a difference between </p>
  
  <ol>
  <li><p>Calling <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.hist.html" rel="noreferrer"><code>hist</code></a> directly on the data to plot </p></li>
  <li><p>Calculating the histogram results (with <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.histogram.html#numpy-histogram" rel="noreferrer"><code>numpy.histogram</code></a>) then plotting with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.plot.bar.html" rel="noreferrer"><code>bar</code></a></p></li>
  </ol>
  
  <h2>Example Data Generation</h2>
  
  <pre><code>%matplotlib inline
  
  import numpy as np
  import pandas as pd
  import scipy.stats as stats
  import matplotlib
  matplotlib.rcParams['figure.figsize'] = (12.0, 8.0)
  matplotlib.style.use('ggplot')
  
  # Setup size and distribution
  size = 50000
  distribution = stats.norm()
  
  # Create random data
  rv = pd.Series(distribution.rvs(size=size))
  # Get sane start and end points of distribution
  start = distribution.ppf(0.01)
  end = distribution.ppf(0.99)
  
  # Build PDF and turn into pandas Series
  x = np.linspace(start, end, size)
  y = distribution.pdf(x)
  pdf = pd.Series(y, x)
  
  # Get histogram of random data
  y, x = np.histogram(rv, bins=50, normed=True)
  # Correct bin edge placement
  x = [(a+x[i+1])/2.0 for i,a in enumerate(x[0:-1])]
  hist = pd.Series(y, x)
  </code></pre>
  
  <h2><code>hist()</code> Plotting</h2>
  
  <pre><code>ax = pdf.plot(lw=2, label='PDF', legend=True)
  rv.plot(kind='hist', bins=50, normed=True, alpha=0.5, label='Random Samples', legend=True, ax=ax)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/71zoC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/71zoC.png" alt="hist plotting"></a></p>
  
  <h2><code>bar()</code> Plotting</h2>
  
  <pre><code>ax = pdf.plot(lw=2, label='PDF', legend=True)
  hist.plot(kind='bar', alpha=0.5, label='Random Samples', legend=True, ax=ax)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/EwRvG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/EwRvG.png" alt="bar plotting"></a></p>
  
  <h2>How can the <code>bar</code> plot be made to look like the <code>hist</code> plot?</h2>
  
  <p>The use case for this is needing to save only the <em>histogrammed</em> data to use and plot later (it is typically smaller in size than the original data).</p>