如何在matlab的imagesc图中添加图例 [英] How to add legend in imagesc plot in matlab

查看:915
本文介绍了如何在matlab的imagesc图中添加图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,创建要打印到文件的图形:

I have the following code, creating figures which I print to files:

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);

我想在颜色栏的右侧添加图例,我尝试使用图例功能进行此操作,但未显示...使用文本功能将其放置在printanle区域之外.有人可以帮忙吗? 谢谢

I want to add legend to the right of the colorbar, and I tried doing so using the legend function, but it is not shown... using the text function places it outside the printanle area. Can anyone help ? Thanks,,,

推荐答案

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

A possible workaround (if I understood you correctly):

 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

这篇关于如何在matlab的imagesc图中添加图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆