Graphics as axis labels in MATLAB

I draw a 7x7 pixel image in MATLAB using the imagesc command:

 imagesc(conf_matrix, [0 1]); 

This is a matrix of confusion between seven different objects. I have a thumbnail of each of the seven objects that I would like to use as tick marks. Is there an easy way to do this?

+2
source share
2 answers

I do not know how easy it is. The XtickLabel axis XtickLabel that define labels can only be strings.

If you need a not-so-easy way, you can do something in the spirit of the following incomplete (in the sense of an incomplete solution) code by creating one label:

 h = imagesc(rand(7,7)); axh = gca; figh = gcf; xticks = get(gca,'xtick'); yticks = get(gca,'ytick'); set(gca,'XTickLabel',''); set(gca,'YTickLabel',''); pos = get(axh,'position'); % position of current axes in parent figure pic = imread('coins.png'); x = pos(1); y = pos(2); dlta = (pos(3)-pos(1)) / length(xticks); % square size in units of parant figure % create image label lblAx = axes('parent',figh,'position',[x+dlta/4,y-dlta/2,dlta/2,dlta/2]); imagesc(pic,'parent',lblAx) axis(lblAx,'off') 

One of the problems is that the label will have the same color map of the original image.

+3
source

@Itmar Katz gives a solution very close to what I want to do, which I designated as β€œaccepted”. In the meantime, I made this dirty decision using the subheadings I gave here for completeness. It only works with an input matrix of a certain size, and only displays well when the shape is square.

 conf_mat = randn (5);
 A = imread ('peppers.png');
 tick_images = {A, A, A, A, A};

 n = length (conf_mat) + 1;

 % plotting axis labels at left and top
 for i = 1: (n-1)
     subplot (n, n, i + 1); 
     imshow (tick_images {i});
     subplot (n, n, i * n + 1);
     imshow (tick_images {i});
 end

 % generating logical array for where the confusion matrix should be
 idx = 1: (n * n);
 idx (1: n) = 0;
 idx (mod (idx, n) == 1) = 0;

 % plotting the confusion matrix
 subplot (n, n, find (idx ~ = 0));
 imshow (conf_mat);
 axis image
 colormap (gray)

enter image description here

+3
source

Source: https://habr.com/ru/post/1340604/


All Articles