我用下面的代码生成我混淆矩阵,这是我发现互联网上:
confmat = C;
labels = {'0', '1', '2', '3', '11' };
numlabels = size(confmat, 1); % number of labels
confpercent = 100*confmat./repmat(sum(confmat, 1),numlabels,1);
imagesc(confpercent);
Mycolors=[0 0.7 0.4; 1 0.9 0.9 ]
colormap(flipud(Mycolors));
textStrings = num2str([confpercent(:)], '%.1f%%\n');
textStrings = strtrim(cellstr(textStrings));
[x,y] = meshgrid(1:numlabels);
hStrings = text(x(:),y(:),textStrings(:), ...
'HorizontalAlignment','center');
midValue = mean(get(gca,'CLim'));
textColors = repmat(confpercent(:) > midValue,1,3);
set(hStrings,{'Color'},num2cell(textColors,2));
set(gca,'XTick',1:numlabels,... 'XTickLabel',labels,... 'YTick',1:numlabels,... 'YTickLabel',labels,... 'TickLength',[0 0]);
虽然我想垂直线添加到我的矩阵值之间分开,以便我可以得到一个类似下一个:
我能得到通过令pColor(confusion_matrix)这些垂直线,但比例都转移到每个网格的角落,我已经拿到了下一张图片:qazxsw POI
不得不应付不同axes
属性,当经典的MATLAB把戏。基本上,我们要创建一个新的axes
对象,将其放置在珍贵的顶部,然后使它透明的(无背景色),所以我们可以看到什么是落后,但我们会继续我们想要的网格线以及可见光右他们。
于是立即示例代码后,添加:
axes
这将让你(数据有所不同一点,因为我随机产生混淆矩阵):
ax1 = gca ; % get handle of initial axes
ax2 = axes ; % create new axe and retrieve handle
lim = [0 numlabels] ; % Prepare X and Y properties
tks = 0:numlabels ;
% superpose the new axe on top, at the same position
set(ax2,'Position', get(ax1,'Position') );
% make it transparent (no color)
set(ax2,'Color','none') ;
% set the X and Y properties
set(ax2, ...
'XLim',lim,'XTick',tks,'XTickLabel','' ,...
'YLim',lim,'YTick',tks,'YTickLabel','' ) ;
% now set your grid properties
set(ax2,'GridColor','k','GridAlpha',1)
当然,现在你必须在你的网格线完全控制,所以你也可以提炼它们是如何出现过的网格属性。一些有趣的特性是:
axes
- 网格线线型GridLineStyle
- 网格线的颜色GridColor
- 网格线透明度GridAlpha
- 线宽有关详细信息,看看在LineWidth
文档
好 !我已经找到了要求的工作让垂直和水平线,这是简单地使用阴谋,并就添加行:
我已经使用了下面的代码在我的问题提到一个结束:
Axes Properties
我用1,2,3和4,因为我有四个类,并在每个类别预测的最终结果,我需要绘制线。希望将是有益的