Skip to content Skip to sidebar Skip to footer

Python Pyplot Legend Scatter

I've got 5 classes and some features that I want to plot. This is the code x_pts = X_test.iloc[:,col_1] y_pts = X_test.iloc[:,col_2] color_seq = y_test plt.scatter(x_pts, y_pts, c=

Solution 1:

Hope this helps:

x = [1, 3, 4, 6, 7, 9]
y = [0, 0, 5, 8, 8, 8]
labels = ['A', 'B', 'C']
colors = [0, 0, 1, 2, 2, 2]
scatter = plt.scatter(x, y,c=colors, cmap='viridis')
plt.legend(handles=scatter.legend_elements()[0], labels=labels)
plt.show()

Output: enter image description here

Post a Comment for "Python Pyplot Legend Scatter"