title: How to plot scatter graph with markers based on column value
body: <p>I am trying to plot a scatter graph on some data with grouping. They are grouped by the column <code>group</code> and I want them to have different <strong>marker styles</strong> based on the group.</p>
  <h3>Minimal working code</h3>
  <pre class="lang-py prettyprint-override"><code>import matplotlib.pyplot as plt
  import pandas as pd
  import numpy as np
  
  colors = ['r','g','b','y']
  markers = ['o', '^', 's', 'P']
  
  df = pd.DataFrame()
  df[&quot;index&quot;] = list(range(100))
  df[&quot;data&quot;] = np.random.randint(100, size=100)
  df[&quot;group&quot;] = np.random.randint(4, size=100)
  df[&quot;color&quot;] = df.apply(lambda x: colors[x[&quot;group&quot;]], axis=1)
  df[&quot;marker&quot;] = df.apply(lambda x: markers[x[&quot;group&quot;]], axis=1)
  
  plt.scatter(x=df[&quot;index&quot;], y=df[&quot;data&quot;], c=df[&quot;color&quot;])
  # What I thought would have worked
  # plt.scatter(x=df[&quot;index&quot;], y=df[&quot;data&quot;], c=df[&quot;color&quot;], marker=df[&quot;marker&quot;])
  plt.show()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/oid2Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oid2Q.png" alt="example_output" /></a></p>
  <h3>What I want</h3>
  <p>I want the groups to have different marker styles as well. For example the red entries will have marker &quot;o&quot; (big dot), green entries with marker &quot;^&quot; (upward triangle) and so on.</p>
  <h3>What I tried</h3>
  <p>I thought</p>
  <pre class="lang-py prettyprint-override"><code>plt.scatter(x=df[&quot;index&quot;], y=df[&quot;data&quot;], c=df[&quot;color&quot;], marker=df[&quot;marker&quot;])
  </code></pre>
  <p>would have worked but nope...</p>
  <pre><code>TypeError: 'Series' objects are mutable, thus they cannot be hashed
  </code></pre>
  <p>I can <code>for</code> loop over the DataFrame and group the entries by their <code>group</code>. Then plot them with the <code>marker</code> argument set with the list defined (like <code>plt.scatter(..., marker=markers[group])</code>. That would result in 4 <code>plt.scatter(...)</code> as there are 4 groups in total. But that is ugly IMO to loop through a DataFrame row by row and I strongly believe there is a better way.</p>
  <p>Thanks in advance!</p>