Allow zooming to resize the axes and maintain axis equal

57 vues (au cours des 30 derniers jours)
Alexander Georgescu
Alexander Georgescu le 17 Juin 2020
Modifié(e) : Ameer Hamza le 18 Juin 2020
Hello Community,
am a tools dev but fairly new to matlab. A task I have is to improve the normal zoom function for our plot.
By default we use a given xlim and ylim and "axis equal" enabled. What we want is that when dragging a rectangle to zoom, we get to see exactly what is inside that rectangle, nothing more.
At the same time this should not break the "axis equal" property.
So that means that the shape of the whole plot has to change as well (aka how the plot is drawn onto the screen. I really lack the right words for this...).
How would one go about doing that?
So far I have experimented a lot with the auto features of Axis to no avail. Also attempted to use ActionPostCallback to set the right xlim and ylims manually but that would require me to know what zoom rectangle the user dragged but that does not seem to be possible.
Huge thanks in advance!

Réponses (1)

Ameer Hamza
Ameer Hamza le 18 Juin 2020
Modifié(e) : Ameer Hamza le 18 Juin 2020
I guess you are trying to change the position of the axes() object, making it small such that the 'axis equal' effect remains on the zoomed portion. This can be done using daspect() and pbaspect() functions. Actually, the following two commands are somewhat equivalent
axis equal
daspect([1 1 1])
However, 'axis equal' can automatically change the limit of the axes object, whereas, daspect adjust the size of axes object such the limit remain same.
You can also write a callback function to automatically call daspect()
plot(1:10)
h = zoom();
h.ActionPostCallback = @(o, e) daspect(e.Axes, [1 1 1]);
Note that the first time you zoom on an axes, it only retains the zoomed region, however, on subsequent zooms, it also retains the outside region. This is a limitation of zoom and not the daspect(). It would have been easier if there was a way to get the limits of the zoomed region, however, it seems that it is not supported.
Another workaround can be to detect the mouse drag by the user, as shown in my answer here: https://www.mathworks.com/matlabcentral/answers/516718-how-can-i-make-an-image-comparison-slider-in-matlab. Combining the mouse drag callback in that answer with the ActionPreCallback() of the zoom() object does seem to give some promising direction.

Catégories

En savoir plus sur Visual Exploration dans Help Center et File Exchange

Tags

Produits


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by