【问题标题】:Multiple subplots with one dynamic super title using annotation使用注释的具有一个动态超级标题的多个子图
【发布时间】:2016-07-24 20:28:45
【问题描述】:

我正在尝试为多个子图使用一个超级标题。我使用annotation 来实现这一点。 annotation 在循环内。问题是annotation 在非动态时工作正常,但不幸的是,当我使用Loop 时我需要更改标题

我使用了以下代码,该代码在标题没有更改时有效。 (这只是随机数的一个例子)

clc;
clear;
a=rand(10,10);
for i=1:3
h(1)=subplot (2,2,1);
plot (a(:,1),a(:,2));
set(h(1),'Position',[.1 .35 .35 .5])
h(2)=subplot (2,2,2);
plot (a(:,1),a(:,2));
set(h(2),'Position',[.55 .35 .35 .5])
annotation('textbox', [0 0.85 1 0.1],'String',...
 'Test text Number=1','EdgeColor', 'none','HorizontalAlignment', 'center')

end

我尝试如下更改annotation 行,但它不起作用

annotation('textbox', [0 0.85 1 0.1],'String',...
 'Test text Number=%d',i,'EdgeColor', 'none','HorizontalAlignment', 'center')

我不想在我的代码中使用外部函数,例如 (suptitle,suplabel..etc)

【问题讨论】:

    标签: matlab plot matlab-figure subplot


    【解决方案1】:

    这将起作用:

    temp=annotation('textbox', [0 0.85 1 0.1],'String',...
    ['Test text Number=',num2str(i)],'EdgeColor', 'none','HorizontalAlignment', 'center')
    

    【讨论】:

    • 非常感谢。请,当我删除最后三行时,代码可以正常工作。我不明白什么时候需要这些行。 drawow pause(1) if i~=3 delete(temp);结束
    • 根据您的选择删除
    • 'drawnow` 帮助您可视化使用pause 绘制的绘图,然后delete 从屏幕上删除之前的注释,以免与之前的注释混在一起以前写的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    相关资源
    最近更新 更多