%% Maintaining the Axes Proportions with Figure Resize
% To maintain a particular shape, you can specify the size of the axes in absolute units such as inches, which are independent of the figure window size. However, this is not a good approach if you are writing a MATLAB program that you want to work with a figure window of any size. A better approach is to specify the aspect ratio of the axes and override automatic stretch-to-fill.
% In cases where you want a specific aspect ratio, you can override stretching by specifying a value for these axes properties:
% DataAspectRatio or DataAspectRatioMode
% PlotBoxAspectRatio or PlotBoxAspectRatioMode
% CameraViewAngle or CameraViewAngleMode
% The first two sets of properties affect the aspect ratio directly. Setting either of the mode properties to manual simply disables stretch-to-fill while maintaining all current property values. In this case, MATLAB enlarges the axes until one dimension of the position rectangle constrains it. For example, set the DataAspectRatio to [1 1 1]. Also set the figure's color to see the relationship between the figure and the axes.

sphere
daspect([1 1 1])
set(gca,'BoxStyle','full','Box','on')
set(gcf,'Color',[0.90 0.90 0.90])

%
% Changing the size and shape of the figure does not change the aspect ratio of the axes.

f = gcf;
f.Position(3) = f.Position(3) * 0.67;

%
% Setting the CameraViewAngle property disables stretch-to-fill, and also prevents MATLAB from readjusting the size of the axes if you change the view.
% Copyright 2019 The MathWorks, Inc.