Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么可以';我是否通过plt.scatter()指定图例?_Python_Matplotlib_Plot_Legend - Fatal编程技术网

Python 为什么可以';我是否通过plt.scatter()指定图例?

Python 为什么可以';我是否通过plt.scatter()指定图例?,python,matplotlib,plot,legend,Python,Matplotlib,Plot,Legend,我正在使用matplotlib。在这里,我无法在打印时通过指定参数label来指定每个打印的文本 我的代码是这样的,它基于散布()通过指定标签工作。但当我变成分散时,它就不起作用了 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 an

我正在使用matplotlib。在这里,我无法在打印时通过指定参数
label
来指定每个打印的文本

我的代码是这样的,它基于<代码>散布()通过指定
标签
工作。但当我变成分散时,它就不起作用了

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()
没有显示任何图例


如何解决此问题?

您正在绘制多少数据集?您是否尝试过简单的plt.legend()
?我尝试过简单的plt.legend(),但仍然没有图例。