Why does the same View property for Axes with different PlotBoxAspectRatio result in different views?

5 次查看(过去 30 天)
I have two axes, of which I've linked the View property. The two have different PlotBoxAspectRatio.
When rotating around in 3D, the two plots behave as I expect. You can overlay the orthogonal axes in the figure below and verify that they are visually aligned:
However, when the plots are rotated into a plane view (elevation = 90°), the same azimuth angle results in a different orientation for each plot:
>> get([a1,a2],'View')
ans =
2×1 cell array
{[45.2690 90]}
{[45.2690 90]}
The plots will align properly when the axes are horizontal or vertical, but become misaligned in between those states. This only happens for plots with different PlotBoxAspectRatio.
What gives? Code to generate the example above is below:
f = figure('Color', 'w'); % Figure window
% Coordinates of drawn object
ax1 = [-1.0, +1.0, NaN, 0.0, 0.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, -1.0, +1.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, 0.0, 0.0, NaN, -1.0, +1.0];
ax2 = [-2.0, +2.0, NaN, 0.0, 0.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, -1.0, +1.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, 0.0, 0.0, NaN, -1.0, +1.0];
% Axes 1
a1 = axes(f, 'Units', 'normalized', 'OuterPosition', [0.0,0.0,0.5,1.0]);
plot3(ax1(1,:),ax1(2,:),ax1(3,:), 'k', 'LineWidth', 1.0)
axis equal vis3d off
rotate3d on
% Axes 2
a2 = axes(f, 'Units', 'normalized', 'OuterPosition', [0.5,0.0,0.5,1.0]);
plot3(ax2(1,:),ax2(2,:),ax2(3,:), 'k', 'LineWidth', 1.0)
axis equal vis3d off
rotate3d on
% Link view property
link = linkprop([a1,a2],'View');
Thanks in advance!

采纳的回答

Gautam
Gautam 2024-9-30
Hi Aaron,
The behaviour arises because of the "axis equal" command. When you use the "axis equal" command, it adjusts the plot to ensure equal scaling on all axes. This command checks the current position and limits of the axes, calculates the "PlotBoxAspectRaio" (by setting it to "auto"), then sets the limits to be auto in the unconstrained dimension. Because the math it uses is transient, applying "axis equal" before setting the final view of the plot, means that the the calculated values are outdated and irrelevant.
One can visualize the behavior of axis equal as effectively adjusting the limits in one dimension to satisfy the (current) aspect ratio constraints.
Thus, if you call "axis equal" after setting the "View", you'll find the corresponding lines to be parallel
f = figure('Color', 'w'); % Figure window
% Coordinates of drawn object
ax1 = [-1.0, +1.0, NaN, 0.0, 0.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, -1.0, +1.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, 0.0, 0.0, NaN, -1.0, +1.0];
ax2 = [-2.0, +2.0, NaN, 0.0, 0.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, -1.0, +1.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, 0.0, 0.0, NaN, -1.0, +1.0];
% Axes 1
a1 = axes(f, 'Units', 'normalized', 'OuterPosition', [0.0,0.0,0.5,1.0]);
plot3(ax1(1,:),ax1(2,:),ax1(3,:), 'k', 'LineWidth', 1.0)
rotate3d on
% Axes 2
a2 = axes(f, 'Units', 'normalized', 'OuterPosition', [0.5,0.0,0.5,1.0]);
plot3(ax2(1,:),ax2(2,:),ax2(3,:), 'k', 'LineWidth', 1.0)
rotate3d on
% Link view property
link = linkprop([a1,a2],'View');
set([a1,a2], "View", [45,90]);
axis(a1, 'equal', 'vis3d', 'off');
axis(a2, 'equal', 'vis3d', 'off');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axes Appearance 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by