Gnuplot混淆矩阵标注显示0值问题求助
解决Gnuplot混淆矩阵标签显示0的问题
问题原因
你的splot标签语句中,using 1:2:3 with labels的写法没有指定标签的显示内容。在Gnuplot的3D绘图模式下,with labels默认会把标签内容设为0,而非第三列的数值——第三列在这里只被当作标签的Z轴位置,不是显示文本。
修正方案
修改标签部分的using语法,显式指定标签内容为数据的第三列(混淆矩阵的数值):
splot \ "../data/reordered_confusion_matrix.dat" matrix using 1:2:3 with image notitle, \ "../data/reordered_confusion_matrix.dat" matrix using 1:2:(0):stringcolumn(3) with labels notitle font 'Arial,10' textcolor rgb 'black'
代码解释
1:2:指定标签的X、Y坐标(对应矩阵的行、列)(0):固定标签的Z轴位置(因为混淆矩阵是2D平面,设为0不影响显示)stringcolumn(3):将第三列的数值转换为字符串,作为标签显示的内容
如果需要格式化数值(比如确保显示整数),可以用sprintf替代stringcolumn:
using 1:2:(0):sprintf("%d", $3)
额外建议
混淆矩阵本质是2D图表,也可以改用plot命令实现,语法更简洁:
plot \ "../data/reordered_confusion_matrix.dat" matrix using 1:2:3 with image notitle, \ "../data/reordered_confusion_matrix.dat" matrix using 1:2:stringcolumn(3) with labels notitle font 'Arial,10' textcolor rgb 'black'
内容的提问来源于stack exchange,提问作者BLaubach
相关产品推荐
相关产品推荐

