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

14 次查看(过去 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 中查找有关 Axes Appearance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by