Problem with axis equal
355 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
broken_arrow
il 19 Mar 2021
Risposto: Walter Roberson
il 22 Mar 2021
I have a problem with the following code:
inputfigure = figure('Name','Test','Numbertitle','off','Units','centimeters','Position',[5 2 40 23],'Visible','on');
sub2 = subplot('Position',[0.05 0.45 0.2 0.5],'Xdir','reverse');
hold on
grid on
axis equal % this causes the problem
sub2.Layer = 'top';
sub2.Units = 'centimeters';
sub2.Position(4) = sub2.Position(3); % this should make the plot square
The last line should make the plot square, but it only works if I remove axis equal. Why is that? I know I can put 'axis equal' afterwards, but I'd still like to know ;) (As a sidenote, it seems weird that 'subplot' does not accept 'units','centimeters' on creation although the lower level 'axes' command does).
2 Commenti
DGM
il 21 Mar 2021
axis equal
sets the 'PlotBoxAspectRatio' property to a calculated value and sets 'PlotBoxAspectRatioMode' property to 'manual' instead of auto. Changing the position property afterwards doesn't change the aspect ratio since it's in manual mode. Are you sure you don't mean to do something like
axis square
instead?
Risposta accettata
Walter Roberson
il 22 Mar 2021
axis equal sets the axes DataAspectRatio to [1 1 1], so that one physical unit in each direction corresponds to one data unit.
It also sets the PlotBoxAspectRatio, which controls the relative ratios of drawing the axes. You can have different sizes of axes drawn while the data to physical ratio might be the same for all three axes.
The PlotBoxAspectRatio is set so as to retain the same data span on the shorter of what x or y was, but accounting for the data units being made uniform. So after axis equal, the visual appearance of the axes is left the same, but the longer of the two distances (in data units) has been adjusted to account for the units now being uniform.
When you set the Position property, the DataAspectRatio is left at [1 1 1], but the PlotBoxAspectRatioMode is set to 'manual' and the PlotBoxAspectRatio reflects the size you set.
Setting axis equal does not constrain the axis Position to be equal x and y span; it constrains the data aspect ratio; and when you set the axis Position manually, it keeps the data aspect ratio in effect.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Discrete Data Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!