Reputation: 4373
I would like to plot a 2x2 confusion matrix in Matlab in such a way that the plot would have percentage values in each of the grid boxes in this way:
In summary I'm asking for how to make a plot like the one above when you're given the percentage values in a matrix:
V = [0.15, 0.30; 0.05, 0.50]
Is it possible to make a plot like that in Matlab? I did think of drawing the vertical lines and then plotting some text into spesific coordinates, but is this the only way to do this?
Upvotes: 2
Views: 3451
Reputation: 35525
Let me show you how you could do it. I did it just for fun!
You can change the size of your input matrix as you wish.
A=[0.3 0.2 ; 0.1 0.7];
sA=size(A);
Aplot=rot90(A,3);
figure;hold on
rectangle('Position',[0,0,sA(2),sA(1)],'Facecolor',[1 1 1],'edgecolor','none')
for ii=0:sA(1)
plot([0 sA(2)], [ii ii],'k','Linewidth',3)
end
for ii=0:sA(2)
plot([ii ii],[0 sA(1)],'k','Linewidth',3)
end
for ii=1:sA(2)
for jj=1:sA(1)
text((ii-1)+0.35,(jj-1)+0.5,strcat(num2str(Aplot(ii,jj)*100),' %'),'fontsize',30)
end
end
margin=0.05;
axis([0-margin sA(2)+margin 0-margin sA(1)+margin])
axis off
With Matlab 2014b and the new graphic engine, smoother option:
Upvotes: 3