pandas: Using color in a scatter plot
<p>I have a pandas dataframe:</p>

<pre><code>--------------------------------------
|   field_0  |  field_1   | field_2  |
--------------------------------------
|     0      |   1.5      |  2.9     |
--------------------------------------
|     1      |   1.3      |  2.6     |
--------------------------------------
|       :                            |
--------------------------------------
|     1      |   2.1      |  3.2     |
--------------------------------------
|     0      |   1.1      |  2.1     |
--------------------------------------      
</code></pre>

<p>I can create a scatter plot for field_1 vs. field_2 like below:</p>

<pre><code>%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
my_df.plot(x='field_1', y='field_2', kind = 'scatter')
</code></pre>

<p>However, I am wondering is it possible to include field_0 in the plot? So when field_0 = 0, the point is blue; when field_1 = 1, the point is red. </p>

<p>Thanks!</p>

<p>you can do it this way:</p>

<pre><code>col = df.field_0.map({0:'b', 1:'r'})
df.plot.scatter(x='field_1', y='field_2', c=col)
</code></pre>

<p>Result:</p>

<p><a href="http://i.stack.imgur.com/TJItk.png" rel="nofollow"><img src="http://i.stack.imgur.com/TJItk.png" alt="enter image description here"></a></p>

python pandas dataframe