<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [30]: df = pd.DataFrame(dict(a=['A', 'B', 'C'], b=[2, 3, 4]))

In [31]: plt.scatter(df['a'], df['b'])
Out[31]: &lt;matplotlib.collections.PathCollection at 0x7f17e17b41d0&gt;"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">30</span>]: <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-en">dict</span>(<span class="pl-s1">a</span><span class="pl-c1">=</span>[<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>, <span class="pl-s">'C'</span>], <span class="pl-s1">b</span><span class="pl-c1">=</span>[<span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>]))

<span class="pl-v">In</span> [<span class="pl-c1">31</span>]: <span class="pl-s1">plt</span>.<span class="pl-en">scatter</span>(<span class="pl-s1">df</span>[<span class="pl-s">'a'</span>], <span class="pl-s1">df</span>[<span class="pl-s">'b'</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">31</span>]: <span class="pl-c1">&lt;</span><span class="pl-s1">matplotlib</span>.<span class="pl-s1">collections</span>.<span class="pl-v">PathCollection</span> <span class="pl-s1">at</span> <span class="pl-c1">0x7f17e17b41d0</span><span class="pl-c1">&gt;</span></pre></div>
<p dir="auto">This works, and produces this:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/167164/33918097-b35d2262-e005-11e7-89a3-31a47647cf7d.png"><img src="https://user-images.githubusercontent.com/167164/33918097-b35d2262-e005-11e7-89a3-31a47647cf7d.png" alt="figure_1" style="max-width: 100%;"></a></p>
<p dir="auto">On the other hand, this doesn't:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [32]: df.plot.scatter(x='a', y='b')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/data/documents/uni/phd/projects/FluxnetTrafficLights/scripts/plots/predictability_plots.py in &lt;module&gt;()                                                                                                     
----&gt; 1 df.plot.scatter(x='a', y='b')

~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in scatter(self, x, y, s, c, **kwds)                                                                                           
   2803         axes : matplotlib.AxesSubplot or np.array of them
   2804         &quot;&quot;&quot;
-&gt; 2805         return self(kind='scatter', x=x, y=y, c=c, s=s, **kwds)
   2806 
   2807     def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None,

~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)                                                                                           
   2625                           fontsize=fontsize, colormap=colormap, table=table,
   2626                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-&gt; 2627                           sort_columns=sort_columns, **kwds)
   2628     __call__.__doc__ = plot_frame.__doc__
   2629 

~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)                                                                                         
   1867                  yerr=yerr, xerr=xerr,
   1868                  secondary_y=secondary_y, sort_columns=sort_columns,
-&gt; 1869                  **kwds)
   1870 
   1871 

~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
   1650         if isinstance(data, DataFrame):
   1651             plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax,
-&gt; 1652                              kind=kind, **kwds)
   1653         else:
   1654             raise ValueError(&quot;plot kind %r can only be used for data frames&quot;

~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, x, y, s, c, **kwargs)
    808             # the handling of this argument later
    809             s = 20
--&gt; 810         super(ScatterPlot, self).__init__(data, x, y, s=s, **kwargs)
    811         if is_integer(c) and not self.data.columns.holds_integer():
    812             c = self.data.columns[c]

~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, x, y, **kwargs)
    783             y = self.data.columns[y]
    784         if len(self.data[x]._get_numeric_data()) == 0:
--&gt; 785             raise ValueError(self._kind + ' requires x column to be numeric')
    786         if len(self.data[y]._get_numeric_data()) == 0:
    787             raise ValueError(self._kind + ' requires y column to be numeric')

ValueError: scatter requires x column to be numeric"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">32</span>]: <span class="pl-s1">df</span>.<span class="pl-s1">plot</span>.<span class="pl-en">scatter</span>(<span class="pl-s1">x</span><span class="pl-c1">=</span><span class="pl-s">'a'</span>, <span class="pl-s1">y</span><span class="pl-c1">=</span><span class="pl-s">'b'</span>)
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">ValueError</span>                                <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-c1">/</span><span class="pl-s1">data</span><span class="pl-c1">/</span><span class="pl-s1">documents</span><span class="pl-c1">/</span><span class="pl-s1">uni</span><span class="pl-c1">/</span><span class="pl-s1">phd</span><span class="pl-c1">/</span><span class="pl-s1">projects</span><span class="pl-c1">/</span><span class="pl-v">FluxnetTrafficLights</span><span class="pl-c1">/</span><span class="pl-s1">scripts</span><span class="pl-c1">/</span><span class="pl-s1">plots</span><span class="pl-c1">/</span><span class="pl-s1">predictability_plots</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>()                                                                                                     
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-s1">df</span>.<span class="pl-s1">plot</span>.<span class="pl-en">scatter</span>(<span class="pl-s1">x</span><span class="pl-c1">=</span><span class="pl-s">'a'</span>, <span class="pl-s1">y</span><span class="pl-c1">=</span><span class="pl-s">'b'</span>)

<span class="pl-c1">~</span><span class="pl-c1">/</span><span class="pl-s1">miniconda3</span><span class="pl-c1">/</span><span class="pl-s1">envs</span><span class="pl-c1">/</span><span class="pl-s1">science</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">6</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">plotting</span><span class="pl-c1">/</span><span class="pl-s1">_core</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">scatter</span>(<span class="pl-s1">self</span>, <span class="pl-s1">x</span>, <span class="pl-s1">y</span>, <span class="pl-s1">s</span>, <span class="pl-s1">c</span>, <span class="pl-c1">**</span><span class="pl-s1">kwds</span>)                                                                                           
   <span class="pl-c1">2803</span>         <span class="pl-s1">axes</span> : <span class="pl-s1">matplotlib</span>.<span class="pl-v">AxesSubplot</span> <span class="pl-c1">or</span> <span class="pl-s1">np</span>.<span class="pl-s1">array</span> <span class="pl-s1">of</span> <span class="pl-s1">them</span>
   <span class="pl-c1">2804</span>         """
-&gt; 2805         return self(kind='scatter', x=x, y=y, c=c, s=s, **kwds)
   2806 
   2807     def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None,

~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)                                                                                           
   2625                           fontsize=fontsize, colormap=colormap, table=table,
   2626                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-&gt; 2627                           sort_columns=sort_columns, **kwds)
   2628     __call__.__doc__ = plot_frame.__doc__
   2629 

~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)                                                                                         
   1867                  yerr=yerr, xerr=xerr,
   1868                  secondary_y=secondary_y, sort_columns=sort_columns,
-&gt; 1869                  **kwds)
   1870 
   1871 

~/miniconda3/envs/science/lib/python3.6/site-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
   1650         if isinstance(data, DataFrame):
   1651             plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax,
-&gt; 1652                              kind=kind, **kwds)
   1653         else:
   1654             raise ValueError("plot kind %r can only be used for data frames"

<span class="pl-c1">~</span><span class="pl-c1">/</span><span class="pl-s1">miniconda3</span><span class="pl-c1">/</span><span class="pl-s1">envs</span><span class="pl-c1">/</span><span class="pl-s1">science</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span><span class="pl-c1">.6</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">plotting</span><span class="pl-c1">/</span><span class="pl-s1">_core</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">data</span>, <span class="pl-s1">x</span>, <span class="pl-s1">y</span>, <span class="pl-s1">s</span>, <span class="pl-s1">c</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
    <span class="pl-c1">808</span>             <span class="pl-c"># the handling of this argument later</span>
    <span class="pl-c1">809</span>             <span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-c1">20</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">810</span>         <span class="pl-en">super</span>(<span class="pl-v">ScatterPlot</span>, <span class="pl-s1">self</span>).<span class="pl-en">__init__</span>(<span class="pl-s1">data</span>, <span class="pl-s1">x</span>, <span class="pl-s1">y</span>, <span class="pl-s1">s</span><span class="pl-c1">=</span><span class="pl-s1">s</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
    <span class="pl-c1">811</span>         <span class="pl-k">if</span> <span class="pl-en">is_integer</span>(<span class="pl-s1">c</span>) <span class="pl-c1">and</span> <span class="pl-c1">not</span> <span class="pl-s1">self</span>.<span class="pl-s1">data</span>.<span class="pl-s1">columns</span>.<span class="pl-en">holds_integer</span>():
    <span class="pl-c1">812</span>             <span class="pl-s1">c</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">data</span>.<span class="pl-s1">columns</span>[<span class="pl-s1">c</span>]

<span class="pl-c1">~</span><span class="pl-c1">/</span><span class="pl-s1">miniconda3</span><span class="pl-c1">/</span><span class="pl-s1">envs</span><span class="pl-c1">/</span><span class="pl-s1">science</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">6</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">plotting</span><span class="pl-c1">/</span><span class="pl-s1">_core</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">data</span>, <span class="pl-s1">x</span>, <span class="pl-s1">y</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
    <span class="pl-c1">783</span>             <span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">data</span>.<span class="pl-s1">columns</span>[<span class="pl-s1">y</span>]
    <span class="pl-c1">784</span>         <span class="pl-k">if</span> <span class="pl-en">len</span>(<span class="pl-s1">self</span>.<span class="pl-s1">data</span>[<span class="pl-s1">x</span>].<span class="pl-en">_get_numeric_data</span>()) <span class="pl-c1">==</span> <span class="pl-c1">0</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">785</span>             <span class="pl-s1">raise</span> <span class="pl-v">ValueError</span>(<span class="pl-s1">self</span>.<span class="pl-s1">_kind</span> <span class="pl-c1">+</span> <span class="pl-s">' requires x column to be numeric'</span>)
    <span class="pl-c1">786</span>         <span class="pl-k">if</span> <span class="pl-en">len</span>(<span class="pl-s1">self</span>.<span class="pl-s1">data</span>[<span class="pl-s1">y</span>].<span class="pl-en">_get_numeric_data</span>()) <span class="pl-c1">==</span> <span class="pl-c1">0</span>:
    <span class="pl-c1">787</span>             <span class="pl-k">raise</span> <span class="pl-v">ValueError</span>(<span class="pl-s1">self</span>.<span class="pl-s1">_kind</span> <span class="pl-c1">+</span> <span class="pl-s">' requires y column to be numeric'</span>)

<span class="pl-v">ValueError</span>: <span class="pl-s1">scatter</span> <span class="pl-s1">requires</span> <span class="pl-s1">x</span> <span class="pl-s1">column</span> <span class="pl-s1">to</span> <span class="pl-s1">be</span> <span class="pl-s1">numeric</span></pre></div>
<p dir="auto">Why does pandas require x to be numeric if matplotlib doesn't?</p>
<p dir="auto">using versions from conda, on Kubuntu 17.10:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="matplotlib                2.1.0            py36hba5de38_0  
pandas                    0.20.3                   py36_0  
python                    3.6.3                h0ef2715_3  "><pre class="notranslate"><code class="notranslate">matplotlib                2.1.0            py36hba5de38_0  
pandas                    0.20.3                   py36_0  
python                    3.6.3                h0ef2715_3  
</code></pre></div>
<p dir="auto">This is another issue I've found in code that used to work:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import pandas as pd
tm = pd.DatetimeIndex(pd.to_datetime([&quot;2014-01-01 10:10:10&quot;]), tz='UTC').tz_convert('Europe/Rome')
df = pd.DataFrame({'tm': tm})
df.set_index(df.tm, inplace=True)
print(df.tm[0].hour)
print(df.index[0].hour)"><pre class="notranslate"><code class="notranslate">import pandas as pd
tm = pd.DatetimeIndex(pd.to_datetime(["2014-01-01 10:10:10"]), tz='UTC').tz_convert('Europe/Rome')
df = pd.DataFrame({'tm': tm})
df.set_index(df.tm, inplace=True)
print(df.tm[0].hour)
print(df.index[0].hour)
</code></pre></div>
<p dir="auto">writes:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="11
10"><pre class="notranslate"><code class="notranslate">11
10
</code></pre></div>
<p dir="auto">It's unclear to me why the time is shifted. If we take a pd.DatetimeIndex which is not directly contained in the df, it works as it should:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tm = pd.DatetimeIndex(pd.to_datetime([&quot;2014-01-01 10:10:10&quot;]), tz='UTC').tz_convert('Europe/Rome')
df = pd.DataFrame({'tm': tm})
df.set_index(tm, inplace=True)
print(df.tm[0].hour)
print(df.index[0].hour)"><pre class="notranslate"><code class="notranslate">tm = pd.DatetimeIndex(pd.to_datetime(["2014-01-01 10:10:10"]), tz='UTC').tz_convert('Europe/Rome')
df = pd.DataFrame({'tm': tm})
df.set_index(tm, inplace=True)
print(df.tm[0].hour)
print(df.index[0].hour)
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="11
11"><pre class="notranslate"><code class="notranslate">11
11
</code></pre></div>