Changing the position of a plot
193 views (last 30 days)
Show older comments
How do you move everything in a figure (plot, axes, axis labels) up while preserving the aspect ratio of the plot? It seems I can do this by setting the OuterPosition, specifically the first two entries, but I don't understand how they work, or how I can figure out what the current values are.
0 Comments
Accepted Answer
Walter Roberson
on 23 Jan 2023
data1 = rand(1,20);
data2 = rand(1,20);
figure()
ax1 = subplot(2,1,1);
plot(data1)
ax2 = subplot(2,1,2)
plot(data2);
figure()
ax1 = subplot(2,1,1);
plot(data1)
ax2 = subplot(2,1,2)
plot(data2);
ax2.Units
ax2.OuterPosition
ax2.OuterPosition(2) = ax2.OuterPosition(2)*2;
Notice how the bottom plot is closer to the upper plot in the second figure.
OuterPosition uses the standard MATLAB conventions: it is a vector of four values, where the first value is the x coordinate of the bottom of the position; the second value is the y coordinate of the left of the position; the third coordinate is the width; the fourth coordinate is the height.
The default (at least for this use) is "normalized" units -- units that are a fraction of the size of the container. In this particular example the container is a figure(), but if you had happened to use uipanel() then the normalized coordinates would be relative to the containing panel.
It is common to switch the Units of an axes to Pixels; if that is done before changing the OuterPosition, then the OuterPosition would report back in that new units and adjustments would be relative to that new Units.
More Answers (0)
See Also
Categories
Find more on Subplots 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!