Surface plot with semilog z-axis: how to keep the same axis limit for iterative plots?

조회 수: 11 (최근 30일)
Hi all,
I have an algorithm which generates 4 surfaces iteratively. I'd like to set the z-axis to semilog scale and keep the same z-axis limit for all iterations. Here is the code:
x = 1:5;
y = 1:5;
axisLim = 0.0007;
for i = 1:4
subplot(1, 4, i)
surf(x, y, errPreStore{i});
axi_lim = [0, axisLim];
zlim(axi_lim)
axis tight
axis square
set(gca, 'ZScale', 'log');
end
However from the surface plot you can see that the z-axis does not remain the same for these 4 plots. How can I fix it? I've attached the test.mat file so you can import and plot.
Thanks!

채택된 답변

dpb
dpb 2017년 5월 3일
편집: dpb 2017년 5월 3일
Use
zlim([zMIN zMAX])
that you want before beginning the iteration.
Didn't read carefully enough, sorry...you're using mutually exclusive commands and the last in effect are those from axis...
doc axis
...
axis tight sets the axis limits to the range of the data and sets the
XLimMode, YLimMode, and ZLimMode properties to auto.
Use axis tight manual to set the limit mode properties to manual.
...
So, right after you set the z-axis limit manually your overwrite it and set it back to 'auto' with the axis tight call.
Try something more like...
for i = 1:4
hAx(i)=subplot(1, 4, i); % save the axes handles always
surf(x, y, errPreStore{i});
end
set(hAx,'zscale','log')
axis(hAx,'square')
axis(hAx,'tight', 'manual')
set(hAx,'zlim',axi_lim)
which results in
  댓글 수: 2
Xh Du
Xh Du 2017년 5월 3일
편집: Xh Du 2017년 5월 3일
Hi,
I modified my code like this:
x = 1:5;
y = 1:5;
load('test.mat')
for i = 1:4
axisLim = 0.0007;
axi_lim = [0, 0.0007];
zlim(axi_lim)
set(gca, 'ZScale', 'log');
subplot(1, 4, i)
surf(x, y, errPreStore{i});
axis tight
axis square
end
It still does not work.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by