title: R function geom_freqpoly equivalent in Python to plot frequency polygons
body: <p>How to plot the frequency polygons in Python?</p>
  
  <p>For example, I can plot density plot like this:</p>
  
  <pre><code>import pandas as pd
  
  x = (1.5,1.5,1.5,1.5,1.5,1.5,1.5,
           2.5,2.5,2.5,
           3.5,3.5,3.5,3.5,3.5,3.5,
           4.5,4.5,
           6.5,6.5,6.5,6.5,6.5,6.5,6.5,6.5)
  
  df = pd.DataFrame({'x': x})
  #df.head()
  
  df.plot(kind='density')
  </code></pre>
  
  <p>This gives:  </p>
  
  <p><a href="https://i.stack.imgur.com/rR5fJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rR5fJ.png" alt="enter image description here"></a></p>
  
  <p>However, I want the polygon like this:</p>
  
  <pre><code>library(ggplot2)
  
  x = c(1.5,1.5,1.5,1.5,1.5,1.5,1.5,
           2.5,2.5,2.5,
           3.5,3.5,3.5,3.5,3.5,3.5,
           4.5,4.5,
           6.5,6.5,6.5,6.5,6.5,6.5,6.5,6.5)
  
  df = data.frame(x=x)
  # head(x)
  
  ggplot(data=df, mapping = aes(x=x)) + 
    geom_freqpoly(binwidth=2)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vZWQV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vZWQV.png" alt="enter image description here"></a></p>
  
  <p><strong>UPDATE</strong><br>
  I tried the solution by @Quang Hoang for a problem given in the book "R for Data Science" by Hadley and got a similar result.</p>
  
  <p>Book:  </p>
  
  <p><a href="https://i.stack.imgur.com/js4FO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/js4FO.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/tEkNk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tEkNk.png" alt="enter image description here"></a></p>
  
  <p>I have saved the nycflights13 data obtained from R and place it in github.</p>
  
  <p>Here is my attempt to obtain the same plot:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  import seaborn as sns
  
  flights = pd.read_csv('https://github.com/bhishanpdl/Datasets/blob/master/nycflights13.csv?raw=true')
  
  not_cancelled = flights.dropna(subset=['dep_delay','arr_delay'])
  not_cancelled.dep_delay.isnull().sum(), not_cancelled.arr_delay.isnull().sum()
  
  delays = not_cancelled.groupby('tailnum')['arr_delay'].mean().reset_index()
  
  
  x = delays.arr_delay.values
  m = int(x.max())
  counts, bins = np.histogram(x, bins=range(-80,m,10))
  plt.plot(bins[:-1]+1, counts)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/sG9z0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sG9z0.png" alt="enter image description here"></a></p>