在Matlab中控制绘图情节

时间:2015-06-17 09:41:36

标签: matlab plot

我按照here制作了一个情节内部情节的步骤,效果非常好。但是,我想更新一些内容"大型情节",但我给图的每次更新都会进入最后创建的情节,即情节内的情节。

如何控制我给出命令的两个图中的哪一个?

小例子:

% Create data
t = linspace(0,2*pi);
t(1) = eps;
y1 = sin(t);
y2 = cos(t);

% Place axes at (0.1,0.1) with width and height of 0.8
figure
handaxes1 = axes('Position', [0.12 0.12 0.8 0.8]); 

hold on
% Main plot
plot(t, y1)
xlabel('t')
ylabel('sin(t)')
set(handaxes1, 'Box', 'off')

% Adjust XY label font
handxlabel1 = get(gca, 'XLabel');
set(handxlabel1, 'FontSize', 16, 'FontWeight', 'bold')
handylabel1 = get(gca, 'ylabel');
set(handylabel1, 'FontSize', 16, 'FontWeight', 'bold')

% Place second set of axes on same plot
handaxes2 = axes('Position', [0.6 0.6 0.2 0.2]);
fill(t, y1.^2, 'g')
set(handaxes2, 'Box', 'off')
xlabel('t')
ylabel('(sin(t))^2')

%Now, I would like to return to the sine plot and add a cosine!
plot(t, y2)

但是,这会导致图中覆盖小图中的fill - 命令,而不是在大图中添加余弦,即使我有hold on。我意识到我可以改变绘图命令的顺序,但是在我当前的项目中,我希望在更大/动画更大的情况下获得小的情节。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在plot命令中指定要使用的轴。例如,要强制它使用您的大轴:

plot(handaxes1, t, y2)

大多数Matlab绘图命令都可以使用相同的技巧。例如,如果您只想为大图而保留图形,可以调用hold(handaxes1, 'on')