如何在matlab中的imagesc plot中添加图例

时间:2012-10-15 19:32:31

标签: matlab legend

我有以下代码,创建我打印到文件的数字:

f=figure;
set(gcf,'Visible','off');
imagesc (exp_genes_sorted_cut);
h=colorbar;
set(gcf,'Colormap',mycmap);

set(gca, 'xtick', 1:num_tissues_displayed);
set(gca, 'xticklabel', tissues, 'fontsize', 14);
ylabel('Genes', 'Fontsize', 18);
xlabel('Tissues', 'Fontsize', 18);

我想在colorbar的右边添加图例,我尝试使用图例功能,但是没有显示...使用文本功能将它放在printanle区域之外。有人可以帮忙吗? 感谢,,,

1 个答案:

答案 0 :(得分:7)

可能的解决方法(如果我理解正确的话):

 N=4;                                                    %  # of data types, hence legend entries
 Data = randi(N,30,30);                                  % generate fake data
 imagesc(Data)                                           % image it
 cmap = jet(N);                                          % assigen colormap
 colormap(cmap)
 hold on
 L = line(ones(N),ones(N), 'LineWidth',2);               % generate line 
 set(L,{'color'},mat2cell(cmap,ones(1,N),3));            % set the colors according to cmap
 legend('A','B','C','D')                                 % add as many legend entries as data

enter image description here

相关问题