using subplot(m,n,p,ax) in a loop
9 次查看(过去 30 天)
显示 更早的评论
Hi, If I have this plot
x = linspace(1,10);
y = sin(x);
plot(x,y)
title('Sine Plot')
And want to assign it to a subplot with the same axes, I will do
ax1 = gca;
subplot(2,1,1,ax1)
But now if I want a new plot at subplot(2,1,2) with the same axes, I can’t do
ax1 = gca;
subplot(2,1,2,ax1)
because it deletes the previous plot. How can I keep both plots?
Cheers, p.
0 个评论
采纳的回答
Ingrid
2015-6-11
you cannot define an axes handle in a subplot command because the subplot command generates an axes
You should just write
h1 = subplot(2,1,1)
plot(h1,x1,y1)
h2 = subplot(2,1,2)
plot(h2,x2,y2)
2 个评论
Ingrid
2017-2-3
when you type
doc image
you can learn that what you want is to not generate a new plot (A high-level function that calls newplot to determine where to draw the graphics objects and sets the following axes properties) as you are currently doing, but that you require A low-level function that adds the image to the current axes without calling newplot. The low-level function argument list can contain only property name/property value pairs. So basically you have to change your call to image so that you are plotting to the currently selected axes
hFig = figure;
for i= 1:12
% Subplot 1
figure(1)
hAX(i) = subplot(4,3,i); % i is the counter of the loop for example
xlim (hAX(i),[0 1]);
ylim (hAX(i),[0 100]);
box(hAX(i),'off');
hold(hAX(i),'all')
image('PropertyName',PropertyValue,...) % fill in for your specific case
colorbar;
end
更多回答(1 个)
Salaheddin Hosseinzadeh
2015-6-11
Just put figure outside the loop.
If you want to change each axis or maybe axes properties, use xlim ylim in your for loop you can only have
for i = 1:N
subplot(1,N);
plot(data);
xlim([-x,x]);
ylim([-y,y]);
end
something like this
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!