【问题标题】:How to add legend in imagesc plot in matlab如何在matlab的imagesc图中添加图例
【发布时间】:2012-10-15 19:32:31
【问题描述】:

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

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 在技术上是图像的图例(即指向特定像素的强度/颜色范围)。如果你想额外描述,你可以使用title()将它放在你的图片上方。
  • 您希望图例显示什么?可以创建虚拟绘图元素,然后将其用作图例。

标签: matlab legend


【解决方案1】:

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

 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-29
    • 2015-08-05
    • 2017-06-07
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 2012-06-30
    • 1970-01-01
    相关资源
    最近更新 更多