I am making a scatter plot for a dataset that looks like this:
x = [1, 1, 2, 2, 3, 3, 4, 4]
y = [1, 2, 3, 4, 1, 2, 3, 4]
labels = [1, 3, 0, 2, 2, 1, 0, 3]
colors = np.array(plt.rcParams['axes.prop_cycle'].by_key()['color'])
plt.scatter(x, y, color=colors[labels])
If I call plt.legend
, only one entry will be shown, for the entire dataset, with the first symbol. How do I create a legend with all four elements in it, displayed as if I had plotted four separate datasets?
Probably relevant: Matplotlib histogram with multiple legend entries
Based on: Matplotlib, how to loop?