我正在使用matplotlib使用以下代码绘制混淆矩阵:fromnumpyimport*importmatplotlib.pyplotaspltfrompylabimport*conf_arr=[[33,2,0,0,0,0,0,0,0,1,3],[3,31,0,0,0,0,0,0,0,0,0],[0,4,41,0,0,0,0,0,0,0,1],[0,1,0,30,0,6,0,0,0,0,1],[0,0,0,0,38,10,0,0,0,0,0],[0,0,0,3,1,39,0,0,0,0,4],[0,2,2,0,4,1,31,0,0,0,2],[0,1,0,0,0,0,0,36,0,2,
我想知道如何标记arrow并在图的图例中显示它。例如如果我这样做arrow(0,1,'dummy',label='Mylabel')legend()我在图例中没有看到任何内容。我希望在图例框中的标签旁边看到一个箭头。 最佳答案 您可以将任意艺术家添加到图例命令,如解释的那样hereimportmatplotlib.pyplotaspltf=plt.figure()arrow=plt.arrow(0,0,0.5,0.6,'dummy',label='Mylabel')plt.legend([arrow,],['Mylabel',])箭