Why does the same View property for Axes with different PlotBoxAspectRatio result in different views?
4 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Gautam
on 30 Sep 2024
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 Comments
More Answers (0)
See Also
Categories
Find more on Axes Appearance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!