Borrar filtros
Borrar filtros

Preserve plot box size while updating data aspect ratio

2 visualizaciones (últimos 30 días)
T A
T A el 9 de Dic. de 2022
Editada: Varun el 20 de Mzo. de 2023
Matlab documentation states that disabling either of the data or plot box aspect ratios turns off stretch-to-fill and causes the axes to immediately resize. However, when changing the data aspect ratio of an axes, I would like the plot box to stay as it is, and instead the XLim and YLim properties to be automatically updated. I have tried several different iterations of the code below, but none have succeeded.
Notably, if the figure window is not docked, then the desired behavior is achieved. And if run line-by-line, then the desired behavior is achieved. But, I'm running some costly figure generation code, so I would rather avoid these less efficient "hacks". I'm using version 2020a, in case it matters.
figure
set(gcf,'windowstyle','docked')
cax=axes;
hold(cax,'on')
cax.YLim=[0,cax.PlotBoxAspectRatio(2)];
cax.PlotBoxAspectRatioMode='manual';
cax.DataAspectRatioMode='manual';
cax.XLimMode='auto';
cax.YLimMode='auto';
cax.DataAspectRatio=[1, 0.5, 1];
  2 comentarios
J. Alex Lee
J. Alex Lee el 10 de Dic. de 2022
I think you will need to calculate the axes dimensions and manually set them.
Varun
Varun el 20 de Mzo. de 2023
Editada: Varun el 20 de Mzo. de 2023
Hello!
Can you please tell me exactly what's going wrong? I ran the code snippet you posted and I got a docked plot of the axes. When I zoomed in on the plot, the plot box does not get resized, and instead the values on the axes changed i.e., the xlim and ylim values got changed. I tried this on both R2022b and R2020a and got the same results. I even tried plotting multiple arrays on the same axes and still, the size does not get affected. So, please let me know exactly how to help!

Iniciar sesión para comentar.

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

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by