Display the exact selected area by zooming in on a surface/image

4 visualizaciones (últimos 30 días)
Hi,
I have an uiaxes on a GUI (appdesigner) on which I draw a 2D surface with axis equal. When I zoom in by selecting an area, I'd like the area displayed to correspond exactly to the one selected (no more, no less). I had this behavior with MATLAB 2019/2020. However, since upgrading to version 2024, I've been able to zoom in, but the initial width/length aspect ratio of the displayed surface remains unchanged. As the background isn't clickable, elongated surfaces are very difficult to manage.
Here's an illustration and an attached .fig. I've tried changing the daspect and DataAspectRatioMode, but couldn't get it right.
If anyone has a solution, I'd love to hear from you!
Thanks in advance.

Respuesta aceptada

Kevin Daigne
Kevin Daigne el 14 de Sept. de 2024
Editada: Kevin Daigne el 14 de Sept. de 2024
From Benjamin's answer (thanks!), I was able to find a solution. It seems that there's a problem because by setting the DataAspectRatio and leaving the PlotBoxAspectRatio to 'auto', the ratio remains constant whatever the zoom. So I wrote the following code for ax the axis containing my surface:
zoomObj=zoom(ax);
set(zoomObj,'ActionPostCallback',@(o,e)zoomCallback(ax));
zoomCallback(ax); % initialization, which is equivalent to an axis equal
function zoomCallback(ax)
limits = axis(ax);
xRange = diff(limits(1:2));
yRange = diff(limits(3:4));
centerX = mean(limits(1:2));
centerY = mean(limits(3:4));
ax.PlotBoxAspectRatio(1:2)=[xRange yRange];
axis(ax,[centerX - xRange/2, centerX + xRange/2, centerY - yRange/2, centerY + yRange/2]);
end

Más respuestas (1)

Benjamin Kraus
Benjamin Kraus el 14 de Ag. de 2024
Editada: Benjamin Kraus el 14 de Ag. de 2024
I downloaded your FIG-file, and it looks like the axes inside has a manually specified DataAspectRatio and PlotBoxAspectRatio. When you zoom, you are also setting manual XLim and YLim, leaving an overconstrained system. MATLAB cannot honor the all four constraints at the same time, so it is ignoring some of them.
This documentation page has some details about this collection of properties and how they behave and interact with one another: Manipulating Axes Aspect Ratio
I'm not sure why this table was removed from the documentation, but if you look at a really old version of the documentation, there is a table that shows how MATLAB responds when you set all of those properties. For example, search on this page for the words "Limits and DataAspectRatio are honored".
The other possibility is that the axes is being resized in a way you don't expect, but because you have the background set to transparent you don't notice. As an experiment, I suggest turning on the axes (set the background back to white) and see if that helps you understand what is happening.

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by