"surf" overwrites axis properties

6 ビュー (過去 30 日間)
Danny Kumpf
Danny Kumpf 2020 年 1 月 7 日
コメント済み: Danny Kumpf 2020 年 1 月 15 日
I think I'm missing something simple here. I'm running this code:
fig = figure;
ax = axes('Parent',fig);
ax.DataAspectRatio = [1 1 1];
ax.XGrid = 'On';
ax.YGrid = 'On';
ax.ZGrid = 'On';
ylabel('y-axis');
zlabel('z-axis');
xlabel('x-axis');
view(3); % Here, the axes have equal aspect ratio and are labeled
[x, y, z] = sphere;
surf(ax, x, y, z); % when this line executes, the aspect ratio changes and the labels disappear
As indicated in the comments, the "surf" command seems to be overriding my axis properties for some reason. If I check the axis object, the properties are still there (ie, calling ax.DataAspectRatio will show [1 1 1], but on the viewable plot, the aspect ratio changes).
Thanks.
  2 件のコメント
darova
darova 2020 年 1 月 7 日
Danny Kumpf
Danny Kumpf 2020 年 1 月 7 日
That seems to work, though I don't understand why. Do you know what's going on behind the scenes with the axis object to make it work like this?

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 1 月 7 日
  1 件のコメント
Danny Kumpf
Danny Kumpf 2020 年 1 月 15 日
Perfect, thanks.

サインインしてコメントする。

その他の回答 (1 件)

Allen
Allen 2020 年 1 月 7 日
Try reordering your properties so that they are assigned after you use the surf function.
fig = figure;
ax = axes('Parent',fig);
[x, y, z] = sphere;
surf(ax, x, y, z); % when this line executes, the aspect ratio changes and the labels disappear
% Assign axes properties after plot functions since they tend to refer to default properties upon first use.
ax.DataAspectRatio = [1 1 1];
ax.XGrid = 'On';
ax.YGrid = 'On';
ax.ZGrid = 'On';
ylabel('y-axis');
zlabel('z-axis');
xlabel('x-axis');
view(3); % Here, the axes have equal aspect ratio and are labeled

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by