How to make zoom in and zoom out functions of a figure work in this situation?

5 vues (au cours des 30 derniers jours)
Leon
Leon le 21 Jan 2020
Commenté : Adam Danz le 22 Jan 2020
I have some x and y values that differ a lot in terms of their ranges. For example, the x values could be
-0.03
-0.02
0
0.01
0.03
but the y values could be
3500
5700
6800
9000
12000
I need to make an x-y plot and let users pinpoint the data points, by using the below coding:
pt = event.IntersectionPoint
Long story short. The above program will be dysfunctional in this case because x and y ranges have such big differences. What I did was to first multiply all the x values with a factor, in this case 100000 before plotting. I then changed the x-axis labels using the below script:
xt = xticks(han01);
for i=1:length(xt)
xt2{i} = num2str(xt(i)/100000);
end
set(han01,'xtickLabel',xt2);
Now, everything works great, except that the zoom in/zoom out functions of the plots are now messed up. Anyone knows how to make the zoom in / zoom out functions work in this situation?
Many thanks!
  3 commentaires
Leon
Leon le 22 Jan 2020
Thanks, Adam!
Below is my pinpointing function that is having the x y range difference issue:
% FIND NEAREST (X,Y,Z) COORDINATE TO MOUSE CLICK
% Inputs:
% hObj (unused) the axes
% event: info about mouse click
% OUTPUT
% coordinateSelected: the (x,y,z) coordinate you selected
% minIDx: The index of your inputs that match coordinateSelected.
% Factor = (max(y)-min(y))/(max(x)-min(x));
pt = event.IntersectionPoint; % The (x0,y0,z0) coordinate you just selected
coordinates = [x(:),y(:),z(:)]; % matrix of your input coordinates
dist = pdist2(pt,coordinates); %distance between your selection and all points
[~, minIdx] = min(dist); % index of minimum distance to points
coordinateSelected = coordinates(minIdx,:); %the selected coordinate
Adam Danz
Adam Danz le 22 Jan 2020
ahhhh I remember this now. You might remember that I recreated the same axis ranges but didn't have the problem but then I realized your plot was much smaller (embedded within an app) which increases the chance of the wrong point being selected (here's the link). But when I tried with your actual app axes, it worked when I selected the outlier data points (link).
If this problem is with the same densely plotted data I'm not sure there will be a good solution to precisely selecting a single coordinate with the mouse. Have you tried zooming into the axes in order to spread out the data points and increase your mouse's precision?

Connectez-vous pour commenter.

Réponses (0)

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by