I am currently trying to import some data in a table into python to create a plot of one variable against another. I also want to group each of the data point by two of the other variable in the same table.
One of the variables (the one I want to assign colour to) only has 3 options. The other variable (the one I want to assign the shape to) only has 5. Both of which I can easily group the data into. The issue just comes with plotting, as not all of the groups contain all 3 options of the "colour" variable. I can get the scatter plot to show shapes or colours easily, it is when I combine them that I have an issue.
At the moment I can make it so that the colour is plotted, but there are two sets of shapes for each data point: one that is the correct shape, and the other just a standard point. If I remove what is causing the double points however, the colours are not correct.
This is my current code (with example data), I have given the colour variable letters, but the real data is as simplistic:
import matplotlib.pyplot as plt
import numpy as np
r = np.array([600, 2000, 980, 1770, 920, 1100, 220])
t = np.array([2.7, 12.67, 10.54, 1.3, 16.1, 0.92, 13.56])
spectra_type = np.array(['A', 'A', 'B', 'A', 'C', 'B', 'A'])
spectra_num = np.array([{'A': 0, 'B': 1, 'C': 2}[i] for i in spectra_type])
i = np.array(['Shape1','Shape2','Shape3','Shape4','Shape5','Shape2','Shape4'])
shape1 = np.where(i=='Shape1')[0]
shape2 = np.where(i=='Shape2')[0]
shape3 = np.where(i=='Shape3')[0]
shape4 = np.where(i=='Shape4')[0]
shape5 = np.where(i=='Shape5')[0]
plt.figure('fig 1')
plt.xlabel('x')
plt.ylabel('y')
plt.scatter(t[shape1], r[shape1], c=spectra_num[shape1], marker='D', label='Shape1')
plt.scatter(t[shape2], r[shape2], c=spectra_num[shape2], marker='^', label='Shape2')
plt.scatter(t[shape3], r[shape3], c=spectra_num[shape3], marker='o', label='Shape3')
plt.scatter(t[shape4], r[shape4], c=spectra_num[shape4], marker='s', label='Shape4')
plt.scatter(t[shape5], r[shape5], c=spectra_num[shape5], marker='*', label='Shape5')
first_legend = plt.legend(loc='upper left')
plt.gca().add_artist(first_legend)
scatter = plt.scatter(t, r, c=spectra_num)
plt.legend(handles=scatter.legend_elements()[0], labels=['A', 'B', 'C'], title='Colour')
This gives me the following graph, as you can see the shapes are all there but are overlayed with another "regular" shape.

Any advice would be much appreciated!



scatter = plt.scatter(t, r, c=spectra_num)at the end of the code which will print scatter circles of different colors on top of the previous scatter