Only plotting on the last of three axes?
2 次查看(过去 30 天)
显示 更早的评论
I have three axes on the same figure. Each axes has its own plot function. The first time the code runs it prints on the correct axes. On the second time the functions are called, all three plots are shown in the last axes in sequence Tried cla, cla reset, and many others Does this have an obvious solution which I am missing?
0 个评论
采纳的回答
Guillaume
2017-11-16
Each axes has its own plot function. What does that mean?
If a figure has several axes, that means you used subplot to create the axis. You need to save the handle of these axis in order to replot in them:
figure;
hax(1) = subplot(1, 3, 1); %save handle of 1st axis
plot(sin(linspace(0, 2*pi, 200)));
hax(2) = subplot(1, 3, 2); %save handle of 2nd axis
plot(sqrt(linspace(0, 5, 200)));
hax(3) = subplot(1, 3, 3); %save handle of 3rd axis
plot(log(linspace(0, 5 , 200)));
To replot in all axis
plot(hax(1), tan(linspace(0, 2*pi, 200))); %plot in first axis
plot(hax(2), linspace(0, 5, 200).^2); %plot in second axis
plot(hax(3), exp(linspace(0, 5, 200))); %plot in 3rd axis
Alternatively, if you don't want to store the axis, you can reissue the subplot command:
subplot(1, 1, 1); %replot in first axis
plot(cos(linspace(0, 2*pi, 200)));
subplot(1, 1, 2); %replot in second axis
plot(linspace(0, 5, 200));
subplot(1, 1, 2); %replot in 3rd axis
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!