<p dir="auto">I'm working in Jupyter/IPython to plot an amount of Words per Day, but am having trouble using datetimes with Regplot. The issues seems to be somewhat akin to <a href="https://github.com/mwaskom/seaborn/issues/257" data-hovercard-type="issue" data-hovercard-url="/mwaskom/seaborn/issues/257/hovercard">#257</a>, though I'm not quite sure of the difference between lmplot and regplot in this regard.</p>
<p dir="auto">A minimal working example, without datetimes but simple timestamps:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt 
import matplotlib.dates as dates
import seaborn as sns
import time
import datetime
import radar
sns.set(style=&quot;whitegrid&quot;, color_codes=True)

data = pd.DataFrame([])

for i in np.arange(1, 10):
    date =  radar.random_datetime(start='2016-05-20', stop='2016-05-25')
    data = data.append(pd.DataFrame({'Date': time.mktime(date.timetuple()), 'Words': i + 100}, index=[0]), ignore_index=True)

points = plt.scatter(x = data['Date'], y = data[&quot;Words&quot;], c=data[&quot;Words&quot;], s=75, cmap=&quot;BrBG&quot;)
plt.colorbar(points)
sns.regplot(x = data['Date'], y = data[&quot;Words&quot;], data=data, scatter=False, color='r')"><pre class="notranslate"><code class="notranslate">%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt 
import matplotlib.dates as dates
import seaborn as sns
import time
import datetime
import radar
sns.set(style="whitegrid", color_codes=True)

data = pd.DataFrame([])

for i in np.arange(1, 10):
    date =  radar.random_datetime(start='2016-05-20', stop='2016-05-25')
    data = data.append(pd.DataFrame({'Date': time.mktime(date.timetuple()), 'Words': i + 100}, index=[0]), ignore_index=True)

points = plt.scatter(x = data['Date'], y = data["Words"], c=data["Words"], s=75, cmap="BrBG")
plt.colorbar(points)
sns.regplot(x = data['Date'], y = data["Words"], data=data, scatter=False, color='r')
</code></pre></div>
<p dir="auto">Which renders a scatterplot with an overlaid regression-line. With the dates as datetimes:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="points = plt.scatter(x = pd.to_datetime(data['Date'], unit='s').dt.to_pydatetime(), y = data[&quot;Words&quot;], c=data[&quot;Words&quot;], s=75, cmap=&quot;BrBG&quot;)
plt.colorbar(points)
sns.regplot(x = pd.to_datetime(data['Date'], unit='s').dt.to_pydatetime(), y = data[&quot;Words&quot;], data=data, scatter=False, color='r')"><pre class="notranslate"><code class="notranslate">points = plt.scatter(x = pd.to_datetime(data['Date'], unit='s').dt.to_pydatetime(), y = data["Words"], c=data["Words"], s=75, cmap="BrBG")
plt.colorbar(points)
sns.regplot(x = pd.to_datetime(data['Date'], unit='s').dt.to_pydatetime(), y = data["Words"], data=data, scatter=False, color='r')
</code></pre></div>
<p dir="auto">However, this latter code fails with the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-7-d6488afe3dcb&gt; in &lt;module&gt;()
      1 points = plt.scatter(x = pd.to_datetime(data['Date'], unit='s').dt.to_pydatetime(), y = data[&quot;Words&quot;], c=data[&quot;Words&quot;], s=75, cmap=&quot;BrBG&quot;)
      2 plt.colorbar(points)
----&gt; 3 sns.regplot(x = pd.to_datetime(data['Date'], unit='s').dt.to_pydatetime(), y = data[&quot;Words&quot;], data=data, scatter=False, color='r')

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in regplot(x, y, data, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, dropna, x_jitter, y_jitter, label, color, marker, scatter_kws, line_kws, ax)
    777     scatter_kws[&quot;marker&quot;] = marker
    778     line_kws = {} if line_kws is None else copy.copy(line_kws)
--&gt; 779     plotter.plot(ax, scatter_kws, line_kws)
    780     return ax
    781 

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in plot(self, ax, scatter_kws, line_kws)
    330             self.scatterplot(ax, scatter_kws)
    331         if self.fit_reg:
--&gt; 332             self.lineplot(ax, line_kws)
    333 
    334         # Label the axes

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in lineplot(self, ax, kws)
    375 
    376         # Fit the regression model
--&gt; 377         grid, yhat, err_bands = self.fit_regression(ax)
    378 
    379         # Get set default aesthetics

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in fit_regression(self, ax, x_range, grid)
    207             yhat, yhat_boots = self.fit_logx(grid)
    208         else:
--&gt; 209             yhat, yhat_boots = self.fit_fast(grid)
    210 
    211         # Compute the confidence interval at each grid point

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in fit_fast(self, grid)
    222         grid = np.c_[np.ones(len(grid)), grid]
    223         reg_func = lambda _x, _y: np.linalg.pinv(_x).dot(_y)
--&gt; 224         yhat = grid.dot(reg_func(X, y))
    225         if self.ci is None:
    226             return yhat, None

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in &lt;lambda&gt;(_x, _y)
    221         X, y = np.c_[np.ones(len(self.x)), self.x], self.y
    222         grid = np.c_[np.ones(len(grid)), grid]
--&gt; 223         reg_func = lambda _x, _y: np.linalg.pinv(_x).dot(_y)
    224         yhat = grid.dot(reg_func(X, y))
    225         if self.ci is None:

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\numpy\linalg\linalg.py in pinv(a, rcond)
   1614     a, wrap = _makearray(a)
   1615     _assertNoEmpty2d(a)
-&gt; 1616     a = a.conjugate()
   1617     u, s, vt = svd(a, 0)
   1618     m = u.shape[0]

AttributeError: 'datetime.datetime' object has no attribute 'conjugate'"><pre class="notranslate"><code class="notranslate">---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-7-d6488afe3dcb&gt; in &lt;module&gt;()
      1 points = plt.scatter(x = pd.to_datetime(data['Date'], unit='s').dt.to_pydatetime(), y = data["Words"], c=data["Words"], s=75, cmap="BrBG")
      2 plt.colorbar(points)
----&gt; 3 sns.regplot(x = pd.to_datetime(data['Date'], unit='s').dt.to_pydatetime(), y = data["Words"], data=data, scatter=False, color='r')

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in regplot(x, y, data, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, dropna, x_jitter, y_jitter, label, color, marker, scatter_kws, line_kws, ax)
    777     scatter_kws["marker"] = marker
    778     line_kws = {} if line_kws is None else copy.copy(line_kws)
--&gt; 779     plotter.plot(ax, scatter_kws, line_kws)
    780     return ax
    781 

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in plot(self, ax, scatter_kws, line_kws)
    330             self.scatterplot(ax, scatter_kws)
    331         if self.fit_reg:
--&gt; 332             self.lineplot(ax, line_kws)
    333 
    334         # Label the axes

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in lineplot(self, ax, kws)
    375 
    376         # Fit the regression model
--&gt; 377         grid, yhat, err_bands = self.fit_regression(ax)
    378 
    379         # Get set default aesthetics

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in fit_regression(self, ax, x_range, grid)
    207             yhat, yhat_boots = self.fit_logx(grid)
    208         else:
--&gt; 209             yhat, yhat_boots = self.fit_fast(grid)
    210 
    211         # Compute the confidence interval at each grid point

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in fit_fast(self, grid)
    222         grid = np.c_[np.ones(len(grid)), grid]
    223         reg_func = lambda _x, _y: np.linalg.pinv(_x).dot(_y)
--&gt; 224         yhat = grid.dot(reg_func(X, y))
    225         if self.ci is None:
    226             return yhat, None

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\seaborn\linearmodels.py in &lt;lambda&gt;(_x, _y)
    221         X, y = np.c_[np.ones(len(self.x)), self.x], self.y
    222         grid = np.c_[np.ones(len(grid)), grid]
--&gt; 223         reg_func = lambda _x, _y: np.linalg.pinv(_x).dot(_y)
    224         yhat = grid.dot(reg_func(X, y))
    225         if self.ci is None:

C:\Python\WinPython-64bit-3.5.2.2Qt5\python-3.5.2.amd64\lib\site-packages\numpy\linalg\linalg.py in pinv(a, rcond)
   1614     a, wrap = _makearray(a)
   1615     _assertNoEmpty2d(a)
-&gt; 1616     a = a.conjugate()
   1617     u, s, vt = svd(a, 0)
   1618     m = u.shape[0]

AttributeError: 'datetime.datetime' object has no attribute 'conjugate'
</code></pre></div>
<p dir="auto">Though the scatterplot does render with the datetimes well-formatted, also on its own. Is there some special method for using datetimes with regplot, or a way to use the timestamps but still format the labels on the x-axis?</p>
<p dir="auto">I would like to use <code class="notranslate">lmplot</code> to visualize polling data for multiple candidates as demonstrated in <a href="http://nbviewer.ipython.org/gist/bwbensonjr/acd185a4b742368baf36" rel="nofollow">this notebook</a>, but I get <code class="notranslate">TypeError: invalid type promotion</code>.</p>
<p dir="auto">I can convert the dates to a <code class="notranslate">Days</code> integer, but then I don't get the date-based axis labels I want. This kind of use of dates is handled transparently when I use R and ggplot2.</p>
<p dir="auto">Here is the code inline:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import pandas as pd
import seaborn as sns
import StringIO

DATA = &quot;&quot;&quot;Date,Candidate,Percent
2014-06-01,Smith,43
2014-06-01,Perkins,33
2014-06-05,Smith,44
2014-06-05,Perkins,31
2014-06-10,Smith,49
2014-06-10,Perkins,28
2014-06-12,Smith,49
2014-06-12,Perkins,25
2014-06-19,Smith,49
2014-06-19,Perkins,27&quot;&quot;&quot;
df = pd.read_csv(StringIO.StringIO(DATA), parse_dates=[&quot;Date&quot;])

# This gives the TypeError
sns.lmplot(&quot;Date&quot;, &quot;Percent&quot;, df, hue=&quot;Candidate&quot;)

# Converting the date objects to an integer works, but gives
# an innapropriately formatted table.
df[&quot;Day&quot;] = df[&quot;Date&quot;].map(lambda d: d.day)
sns.lmplot(&quot;Day&quot;, &quot;Percent&quot;, df, hue=&quot;Candidate&quot;)"><pre class="notranslate"><code class="notranslate">import pandas as pd
import seaborn as sns
import StringIO

DATA = """Date,Candidate,Percent
2014-06-01,Smith,43
2014-06-01,Perkins,33
2014-06-05,Smith,44
2014-06-05,Perkins,31
2014-06-10,Smith,49
2014-06-10,Perkins,28
2014-06-12,Smith,49
2014-06-12,Perkins,25
2014-06-19,Smith,49
2014-06-19,Perkins,27"""
df = pd.read_csv(StringIO.StringIO(DATA), parse_dates=["Date"])

# This gives the TypeError
sns.lmplot("Date", "Percent", df, hue="Candidate")

# Converting the date objects to an integer works, but gives
# an innapropriately formatted table.
df["Day"] = df["Date"].map(lambda d: d.day)
sns.lmplot("Day", "Percent", df, hue="Candidate")
</code></pre></div>