title: How can you add a trendline to a seaborn's lineplot?
body: <p>Here's what I'm trying to recreate in Seaborn (this was done with Matplotlib)</p>
  
  <p><a href="https://i.stack.imgur.com/vAz0z.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vAz0z.jpg" alt="enter image description here"></a></p>
  
  <p>I see in Seaborn you could use a <code>regplot()</code> but this one is for scatter charts. Anyway, if I try to use it, it won't work because the <code>x</code> are <code>datetime</code>, so I did a mixture of Seaborn and Matplotlib, it works, but I don't like it, I think there must be a better way, Seaborn only.</p>
  
  <pre><code>x = range(0, len(hom.fecha))
  
  plt.figure(figsize=(12, 9))
  plt.style.use('fivethirtyeight')
  
  chart = sns.lineplot(x='fecha', y='n', data=df, 
                       hue='sexo', markers=True)
  chart.set(title='Personas Migrantes', ylabel='# Personas', xlabel="Fecha")
  
  # Linear regressions for each sex
  z = np.polyfit(x, hom.n, 1)
  p = np.poly1d(z)
  plt.plot(hom.fecha, p(x), c="b", ls=":")
  
  z = np.polyfit(x, muj.n, 1)
  p = np.poly1d(z)
  plt.plot(hom.fecha, p(x), c="r", ls=':')
  </code></pre>
  
  <p>I get this picture:</p>
  
  <p><a href="https://i.stack.imgur.com/Ik35X.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ik35X.jpg" alt="enter image description here"></a></p>
  
  <p>Which I think is much more pleasant than the first one, but I just don't get how to add the trend lines using only seaborn.</p>
  
  <p>Any idea?</p>
  
  <p>=== EDIT ===</p>
  
  <p>If I use <code>regplot()</code> it throws an exception...</p>
  
  <pre><code>sns.regplot(x="fecha", y="n", data=df)
  </code></pre>
  
  <p>This one... (it plots something tho, like a scatter chart, with points)</p>
  
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-70-0f60957abc3f&gt; in &lt;module&gt;
  ----&gt; 1 sns.regplot(x="fecha", y="n", data=df)
  
  blah blah blah
  
  TypeError: unsupported operand type(s) for *: 'Timestamp' and 'float'
  </code></pre>