0

I'm using matplotlib. Here I cannot specify the text for each plot by specifying parameter label when plotting.

My code is like this and it's based on this thread. scatter() works by specifying label. But when I changed into scatter, it doesn't work.

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for i in range(np.min((range(len(data)), 200))):
    label = ""
    if predictedLabels[i] == 0 and groundtruthLabels[i] == 0:
        ax.scatter(data[i,1], data[i,2], data[i,3], c='b', marker='1', label='TN')
    if predictedLabels[i] == 1 and groundtruthLabels[i] == 0:
        ax.scatter(data[i,1], data[i,2], data[i,3], c='r', marker='1', label='FN')
    if predictedLabels[i] == 0 and groundtruthLabels[i] == 1:
        ax.scatter(data[i,1], data[i,2], data[i,3], c='r', marker='o', label='FP')
    if predictedLabels[i] == 1 and groundtruthLabels[i] == 1:
        ax.scatter(data[i,1], data[i,2], data[i,3], c='b', marker='o', label='TP')
# axis
ax.set_xlabel('Dim 1')
ax.set_ylabel('Dim 2')
ax.set_zlabel('Dim 3')
# legend
plt.legend(loc='upper left', numpoints=1, ncols=3, fontsize=8, bbox_to_anchor=(0,0))

plt.show()

No legend is showing.

How do I fix this?

Community
  • 1
  • 1
SolessChong
  • 3,370
  • 8
  • 40
  • 67

0 Answers0