Borrar filtros
Borrar filtros

Problem with axis equal

307 visualizaciones (últimos 30 días)
broken_arrow
broken_arrow el 19 de Mzo. de 2021
Respondida: Walter Roberson el 22 de Mzo. de 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 comentarios
DGM
DGM el 21 de Mzo. de 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?
broken_arrow
broken_arrow el 22 de Mzo. de 2021
Editada: broken_arrow el 22 de Mzo. de 2021
Thanks for explaining. I know about axis square, I just wanted to improve my understanding ;). So what changes if I modify the 'position' property afterwards? The position value is still updated, but what does that nominal change of size actually do if it doesn't really influence the plot size?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Mzo. de 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.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by