Scatter plots in Pandas: Plot by category with different color and shape combinations
<p>I would like to plot a data-set by its categories, using geometric shapes such as circle, triangle and square to represent category 1 and colors to represent category 2. The output would have varying combination of the geometric shapes and colors and the legend would list the attributes of the categories separately i.e.:</p>

<p>circle   = a  <br/>
triangle = b  <br/>  square   = c  <br/></p>

<p>red      = I  <br/>
green    = II <br/> 
blue     = III<br/>         </p>

<p>Looking for solutions I found following posts which would only give solutions for one specific geometric shape having one specific color.</p>

<ul>
<li><a href="https://stackoverflow.com/questions/27711078/scatter-plots-in-pandas-pyplot-how-to-plot-by-category-with-different-markers">How to plot by category with different markers</a></li>
<li><a href="https://stackoverflow.com/questions/21654635/scatter-plots-in-pandas-pyplot-how-to-plot-by-category">How to plot by category</a></li>
</ul>

<p>I tried to work something out with the code from one of the posts but without success.</p>

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

np.random.seed(1983)
num = 10
x, y = np.random.random((2, num))
cat1 = np.random.choice(['a', 'b', 'c'], num)
cat2 = np.random.choice(['I', 'II', 'III'], num)
df = pd.DataFrame(dict(x=x, y=y, cat1=cat1, cat2=cat2))

groups = df.groupby(['cat1', 'cat2'])

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>