Use of timestamp or datetime object for colorcoding of a scatterplot?
<p>I do have a list of data: </p>

<pre><code>a = [[Timestamp('2015-01-01 15:00:00', tz=None), 53.0, 958.0],
     [Timestamp('2015-01-01 16:00:00', tz=None), 0.0, 900.0],
     [Timestamp('2015-01-02 11:00:00', tz=None), 543.0, 820.0], .....]
</code></pre>

<p>My goal is to plot the second element of each list entry vs. the third element of each list entry colorcoded by the timestamp.</p>

<pre><code>import matplotlib.pyplot as plt
fig, ax = plt.subplots()
smap = ax.scatter(a[:,1], a[:,2]) 
plt.show()
</code></pre>

<p>As soon as I change the line for plotting to 
    <code>smap = ax.scatter(a[:,1], a[:,2], c = a[:,0])</code></p>

<p>I receive the error message: </p>

<blockquote>
  <p>'Timestamp' object has no attribute 'view'.</p>
</blockquote>

<p>I think my general question is:
Is there any solution in Python to plot two columns of data color-coded by date using a third column which is a timestamp or datetime-object?</p>

<pre><code>a = [[pd.Timestamp('2015-01-01 15:00:00', tz=None), 53.0, 958.0], 
     [pd.Timestamp('2015-01-01 16:00:00', tz=None), 0.0, 900.0], 
     [pd.Timestamp('2015-01-02 11:00:00', tz=None), 543.0, 820.0]]

df = pd.DataFrame(a).add_prefix('Col_')
df
</code></pre>

<p><a href="http://i.stack.imgur.com/Gw5X8.png" rel="nofollow"><img src="http://i.stack.imgur.com/Gw5X8.png" alt="Image"></a></p>

<pre><code>df.dtypes

Col_0    datetime64[ns]
Col_1           float64
Col_2           float64
dtype: object
</code></pre>

<p>Map each color to every value present in the <code>datetime</code> column by defining a list of desired colors inside a dictionary.</p>

<pre><code>c_dict = df['Col_0'].map(pd.Series(data=list('rgb'), index=df['Col_0'].values).to_dict())
df.plot.scatter(x='Col_1', y='Col_2', c=c_dict, alpha=0.8, title='Scatter-Plot')
</code></pre>

<p><a href="http://i.stack.imgur.com/Jsoeq.png" rel="nofollow"><img src="http://i.stack.imgur.com/Jsoeq.png" alt="Image"></a></p>

<p>It wouldn't be practical to use a <code>list</code> and populate colors for every value to be mapped against. In such cases, you are better of using colormaps to do the mapping.</p>

<pre><code>c_dict = df['Col_0'].map(pd.Series(data=np.arange(3), index=df['Col_0'].values).to_dict())
df.plot.scatter(x='Col_1', y='Col_2', c=c_dict, title='Scatter-Plot', cmap=plt.cm.rainbow)
</code></pre>

<p><a href="http://i.stack.imgur.com/5pniu.png" rel="nofollow"><img src="http://i.stack.imgur.com/5pniu.png" alt="Image"></a></p>

python pandas matplotlib