I draw a shape representing a grid of colors / shades based on values ββfrom a 4x5 matrix.
The signs of the labels along the X and y axis are set using text from an array of cells.
Y axis labels exist on 2 levels,
% y ticks, 2 levels ylabelnames = {'team1','set1';'team1','set2';'team2','set1';'team2','set2'};
I would like the y-axis label labels to be either
1) draw 2 lines so that they correspond to two lines of text that were superimposed on the squares of the plot, i.e. "command #" on the first line and "install #" on the second line of each line of imagesc, or
2) rotate the label "team1" to expand along the first two lines and rotate the label "team2" to cover the last two lines so as not to repeat the use of the command 'team1' 'team2' in the marking.
All my code is:
%% Plot Matrix = rand(4,5); Matrix2 = rand(4,5); % y ticks, 2 levels ylabelnames = {'team1','set1';'team1','set2';'team2','set1';'team2','set2'}; xlabelnames = {'group1','group2','group3','group4','group5'}; sigfig = 2; spacer = '\n'; % Font sizes plotFontSize = 8; labelFontSize = 8; plotWidth = 500; plotLength = 300; imagesc(abs(Matrix)) colormap('gray') colormap(flipud(colormap)) caxis([0 2]) for rows = 1:size(Matrix,1) for columns = 1:size(Matrix,2) if abs(Matrix2(rows,columns))<= 0.5 % Show 2nd values less than 0.5 num = Matrix2(rows,columns); num = vpa(num,sigfig); num = ['= ' char(num)]; rval = sprintf('%0.2g', Matrix(rows,columns)); message = sprintf([ 'val= ' rval spacer 'val2' num '' ]); text(columns,rows, message,'HorizontalAlignment','center',... 'FontSize',plotFontSize,'FontName','Times New Roman'); end end end % Put on tick labels set(gca,'Ticklength', [0 0],'YTick',1:size(Matrix),'XTick',1:length(xlabelnames),... 'YTickLabel',ylabelnames,'XTickLabel',xlabelnames,... 'FontSize',labelFontSize,'FontName','Times New Roman')
If you run this, you will see that only the first column of y-labels is used, although there is enough space to place two lines of text in the imagesc line.
I really thought of a scary hacking method that I should use
ylabel('team1 team2')
with huge spaces between labels to evenly distribute them between y-lines, but it is not convenient if I increased the size of my matrix, so I would prefer not to do it this way.
Is there a way to achieve multi-level labeling of labels that I need?
Thanks!