【发布时间】:2012-12-01 10:05:12
【问题描述】:
我正在尝试找到一种更好\更紧凑的方法来将许多“文本块”(我称“文本块”一些具有多行的文本)添加到图形中。例如下图:
我用来生成这个图的代码是:
x=-4*pi:pi/20:4*pi;
y=cos(x);
% generate positions for the text blocks
[ypos,xpos]=find(ismember(y,max(y))); % finds multiple maxima
% generate random data to be presented
info1=rand(1,numel(xpos)); info2=rand(1,numel(xpos)); info3=rand(1,numel(xpos));
plot(x,y);
ylim([-1.1 1.4])
% generate the "text blocks"
text(x(xpos),ypos+0.3,strcat('A_{',num2str((1:numel(xpos))'),'}=',num2str(info1','%0.1f')),'FontSize',8);
text(x(xpos),ypos+0.2,strcat('B_{',num2str((1:numel(xpos))'),'}=',num2str(info2','%0.1f')),'FontSize',8);
text(x(xpos),ypos+0.1,strcat('C_{',num2str((1:numel(xpos))'),'}=',num2str(info3','%0.1f')),'FontSize',8);
%...
%... etc
我知道可以使用元胞数组添加多行文本字符串,方法是将字符串变量定义为每个元胞一行一行的元胞数组。例如:
text(x,y,{'line 1' ; 'line 2' ; 'line 3'});
但是,这也需要每个文本块一行代码,所以它不能解决多文本块的情况...
我的问题是: 有没有办法在单行或更一般的意义上添加这些文本块,比如我有 n 个文本块,每个文本块都有一些可变数量的文本行?
【问题讨论】:
-
点是你想要一种单班轮版本吗?
标签: matlab plot matlab-figure