【发布时间】:2017-12-06 10:53:03
【问题描述】:
我必须生成不同传感器数据的图。这些应该打印在每个子图中。生成绘图后,应使用一些矩形对其进行注释以突出显示不同的特征。之后,这些矩形应该用一个文本进行注释,用一个简短的词来描述所属类。
令人惊讶的是,相同的代码正在另一个脚本中工作,我不使用子图,而只使用一个谱图。 我已经用注释(gcf,...)替换了注释(h,...),应该是一样的。添加 tempplot 而不是 h,这对我来说很有意义,
Sensorinput = rand(100,6);
Naminginput = {'a' 'b' 'c' 'd' 'e' 'f'}
sampledExperiment = [10, 10, 0;
30,10, 1;
50,10, 0;
70,10, 1;
]
experimentnaming = {0, 'classA';
1, 'classB'
}
samplerate = 10;
h = figure;
for index = 1:1:length(Sensorinput(1,:))
tempplot = subplot(length(Sensorinput(1,:)),1,index);
plot(Sensorinput(:,index));
title(Naminginput(index));
pos = get (tempplot, 'position')
step = pos(3)/length(Sensorinput(:,index));
for index=1:1:length(sampledExperiment)
annotation(h, "rectangle",[pos(1)+step*sampledExperiment(index,1),pos(2),step*sampledExperiment(index,2),pos(4)]);
y = ylim;
for namingindex=1:1:length(experimentnaming(:,1))
if experimentnaming{namingindex,1}==sampledExperiment(index,3)
text(sampledExperiment(index,1)/samplerate,y(2),experimentnaming(namingindex,2),'rotation',90);
end
end
end
end
我希望这些框与底层子图具有相同的高度。另外,我期待文本(显然打印为堆栈)作为框的注释。 但这是我目前得到的结果:wrong result。此外,当我调整窗口大小时,这些框不会正确缩放。 wrong_small_window。 这主要是什么工作:working with single figure。用子图的全高绘制矩形并添加文本。这是使用相同的代码创建的,但没有子图。
希望你能帮忙?
【问题讨论】:
-
仍然不确定你在问什么,也许你可以注释你的图像/放一张手绘图/正确的例子?此外,这里的代码没有意义,因为它不是一个独立的示例。考虑编写一个可以复制/粘贴并直接在 matlab 中运行的最小工作示例。但是,作为一般建议,如果您想要微调手动控制,我建议直接使用
axes放置“子图”而不是subplot命令;您可以使用line在您想要的位置手动绘制框; -
(cont.) 最后,如果您希望文本沿 x 轴移动而事实并非如此,那么您可能在
text参数中指的是namingindex而不是index,因为后者在你的内部 for 循环内不会改变。 -
感谢您的 cmets。我为没有子图的程序添加了一些示例和图像的代码,它运行良好。希望现在更清楚了。
标签: octave matlab-figure subplot