title: How to change marker and color in matplotlib for a specific column value?
body: <p>I have a data file including 3 columns. The first 2 columns represent coordinates, the third one is a string value like 'foo', 'bar' or 'ter'.</p>
  
  <p>I would like to display with python's matplotlib based on this label, different marker and color. Example:</p>
  
  <ul>
  <li>foo => red circle </li>
  <li>bar => green triangle</li>
  <li>ter => black square</li>
  </ul>
  
  <p>What I did till now is:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  coordData = np.genfromtxt("mydata.csv", usecols=(0,1), delimiter=",", dtype=None)
  coordLabels = np.genfromtxt("mydata.csv", usecols=2, delimiter=",", dtype=None)
  
  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.scatter(coordData[:, 0], coordData[:, 1], c="r", marker="o") 
  plt.show()
  </code></pre>
  
  <p>How can I switch marker and color based on the <code>coordLabels</code> values?</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>Based on the suggestion I made some changes:</p>
  
  <pre><code>coordData = np.genfromtxt("mydata.csv", usecols=(0, 1), delimiter=",", dtype=None)
  coordLabels = np.genfromtxt("mydata.csv", usecols=2, delimiter=",", dtype=None)
  
  fig = plt.figure()
  ax = fig.add_subplot(111)
  
  uniqueVals = np.unique(coordLabels)
  
  markers = ['^', 'o', '*']
  colors = { '^' : 'r',
             'o' : 'b',
             '*' : 'g'}
  
  for marker, val in zip(markers, uniqueVals):
      toUse = coordLabels == val
      ax.scatter(coordData[toUse,0], coordData[toUse,1], c = colors[marker], marker=marker)
  
  plt.show()
  </code></pre>