【问题标题】:MATLAB - Add legend next to some chosen plots in a subplot - for loopMATLAB - 在子图中的一些选定图旁边添加图例 - for 循环
【发布时间】:2012-06-21 21:58:57
【问题描述】:

我想在子图中添加图例,但仅适用于某些图。 这是我的代码:

for j = 1:length(FL)
  for i = 1:length(index_list)
    pos=pos+1;
    subplot(size(FL,1),length(index_list), pos)
    legend(num2str(ms_list(i)), 'Location', 'NorthOutside');
    imagesc(imread(FL{j,:},index_list(i)))
    if i==1
        legend(FL(j),'Location', 'WestOutside')

  end 
end

子图包含从多帧 .tif 文件中提取的帧。所需帧的索引位于 index_list(列)中。所需文件的路径位于 FL(行)中。我想在图中添加的是每行左侧的文件名和绘制的每个图像的帧索引。 ms_list 包含以毫秒为单位的等效索引,这实际上是我想要显示的。 这样做会在循环中的每个段落返回“Plot empty”。

有什么想法吗?

谢谢

JC

【问题讨论】:

    标签: matlab for-loop legend matlab-figure subplot


    【解决方案1】:

    从您的描述和代码来看,legend 似乎不是您想要的;相反,您需要一个标题(在图上方)和 ylabel(在某些图的左侧)。 legend 是为绘图内的特定对象赋予标签,例如线条系列。

    for j = 1:length(FL)
      for i = 1:length(index_list)
        pos=pos+1;
        subplot(size(FL,1),length(index_list), pos)
        title(num2str(ms_list(i))); %#<---title here
        imagesc(imread(FL{j,:},index_list(i)))
        if i==1
            ylabel(FL(j)) %#<---ylabel here    
        end 
      end
    end
    

    您收到错误的原因是您将legend 应用于一组空的轴。 legend 标记轴的子节点;没有孩子,没有标签,因此错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-21
      • 2011-06-13
      • 2015-10-10
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 2017-08-21
      相关资源
      最近更新 更多