Auto axes limits when 'DataAspectRatioMode' is 'manual'?

1 view (last 30 days)
Hello everybody,
I have a plot where I want to put 'DataAspectRatio' to [1 1 1] ('DataAspectRatioMode' becomes 'manual') so that e.g. 1 unit on x- and y-axis both correspond to the same size on the screen in terms of axis length. This is because the plot is intended to show kartesian world coordinates, so of course I don´t want the plot to be distorted.
The problem now is, that when I resize the figure window there is much unused space to the sides of the plot area, because Matlab does not seem to automatically adjust the axes limits or the 'PlotBoxAspectRatio' when resizing the window.
Look at this simple example:
f = figure;
a = axes;
set(a, 'DataAspectRatio', [1 1 1])
Now when you resize the window divergent from a width/height ratio of 1:1, either at the top and bottom or on the left and right a huge gap appears.
How can I tell Matlab to use the full axes space even when using a manual 'DataAspectRatio'?
Thanks a lot in advance!

Answers (1)

Walter Roberson
Walter Roberson on 23 Oct 2016
When you resize the figure or an axes, MATLAB does not alter the axes limits automatically, so if your aspect ratio is fixed, you can end up with gaps. If you want the axes limits to be changed, you should set up a figure callback that adjusts the axes bounds.
In R2014a and earlier, you should use the figure ResizeFcn callback.
In R2014b, the functionality of that changed and it might now be more appropriate to use SizeChangedFcn callback.
Either way, you would check the new size, possibly adjust the Position of the axes, and possibly adjust the axes XLim and YLim
Note: the ResizeFcn historically also got executed when you print; it has connections to the figure PaperPosition and PaperSize properties that way -- that is, a resize is done to fit the paper size, rendering is done, and then it is resized back to what it was before.

Categories

Find more on Specifying Target for Graphics Output 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!