[英]How to add legend in imagesc plot in matlab
我有以下代码,创建我打印到文件的数字:
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区域之外。 有人可以帮忙吗? 谢谢,,,
一种可能的解决方法(如果我理解正确的话):
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.