How to change the shape of the marker depending on a column variable?
<p>I am trying to create a scatter plot for a csv file in python which contains 4 columns <code>x</code>, <code>y</code>, <code>TL</code>, <code>L</code>. I am supposed to plot <code>x</code> versus <code>y</code> and change the color of the marker based on the <code>class ID</code> in the <code>TL</code> column which I have achieved in the below code.</p>

<pre><code>import pandas as pd    
from matplotlib import pyplot as plt    
import numpy as np

df=pd.read_csv('knnDataSet.csv')  
df.columns=['SN','x','y','TL','L']

color=['red','green','blue']

groups = df.groupby('TL')

fig, ax = plt.subplots()

for name, group in groups:    
    ax.plot(group.x, group.y, marker='o', linestyle='', ms=12, label=name)

ax.legend()    
plt.show()
</code></pre>

<p>Also, I need to  change the shape depending on whether the marker has a label in the <code>L</code> column or not, but I dont know how to update my code to fit this requirement. </p>

<p>Here is the link for the <code>knnDataSet.csv</code> file:
<a href="https://www.dropbox.com/s/d9fzjs1pkmhyzqw/knnDataSet.csv?dl=0" rel="nofollow"><em>knnDataSet.csv</em></a> </p>

<p>You probably want something like this:</p>

<pre><code>import pandas as pd
from matplotlib import pyplot as plt
import numpy as np

df=pd.read_csv('knnDataSet.csv')
df.columns=['SN','x','y','TL','L']
color=['red','green','blue']

groups = df.groupby('TL')

fig, ax = plt.subplots(figsize=(11,8))

for name, group in groups:   
    for x in group.values:
        if np.isnan(x[4]):
            ax.plot(x[1], x[2], marker='x', linestyle='', ms=12)
        else:
            ax.plot(x[1], x[2], marker='o', linestyle='', ms=12)                       

#ax.legend()
plt.show()
</code></pre>

<p>If a label in the L column is <strong>NOT</strong> defined then the marker will be <code>X</code><br>
If a label in the L column <strong>IS</strong> defined then the marker will be <code>O</code></p>

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

python matplotlib scatter-plot markers