Synchronising data tip location on three plots

26 visualizzazioni (ultimi 30 giorni)
Matt
Matt il 19 Ott 2016
Modificato: ali amini il 14 Mar 2023
Hi all,
I have a GUI with three axes plots. When the user uses the data tip on one graph, I want it to appear on the other two, in the same place. When one is moved, I want the others to follow. How could I do this?
I am trying to set the position of a data tip on a graph programatically, but struggling.
fig = figure;
z = peaks;
plot(z(:,30:35))
dcm_obj = datacursormode(fig);
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on')
disp('Click line to display a data tip, then press Return.')
% Wait while the user does this.
pause
c_info = getCursorInfo(dcm_obj);
% Make selected point move
c_info.Position = [2,2] % set position
How would I set the data cursors position?
Is there a better way to make data tips appear on the other two plots in my GUI, and synchronise their location?
I have found linkprop function but not sure how to use it to be honest.
Thanks,
Matt
  2 Commenti
Matt
Matt il 24 Ott 2016
Hi, Does anyone have any more thoughts on this? I am struggling to implement this! Thanks in advance, Matt.
Matt
Matt il 24 Ott 2016
I have found this but I am unsure where to begin to adapt it for my GUI.
I would like the crosshairs and x and y coordinates though...
I have also found this, and it works very well, but you cannot drag the data tips with the mouse, and there is not a vertical crosshair that would span my three subplots

Accedi per commentare.

Risposte (2)

Walter Roberson
Walter Roberson il 19 Ott 2016
It is possible to move the cursor... but I have not figured out how to control where it goes.
dcm_obj = datacursormode(fig);
then
here = dcm_obj.CurrentCursor.Position
dcm_obj.CurrentCursor.moveTo([-10,200])
there = dcm_obj.CurrentCursor.Position
I have not figured out how the argument such as [-10,200] relates to where the cursor ends up. It does seem repeatable, but I have not figured out the coordinate system.
  2 Commenti
Matt
Matt il 19 Ott 2016
Modificato: Matt il 19 Ott 2016
Thanks, that works. I thought it placed the cursor at the nearest data point but it doesn't seem to - odd.
fig = figure;
z = peaks;
plot(z(:,30:35))
dcm_obj = datacursormode(fig)
disp('Place the data cursor on graph and press enter')
pause
here = dcm_obj.CurrentCursor.Position
dcm_obj.CurrentCursor.moveTo([10,-3.7])
there = dcm_obj.CurrentCursor.Position
So... now, how can we link the position of three data tip cursors?
Walter Roberson
Walter Roberson il 19 Ott 2016
When I used moveTo the destinations did not seem to have all that much relationship to the coordinates passed.
Perhaps you could set their UpdateFcn to move the other cursors with moveTo ?
You might also need to use dcm_obj.updateDataCursors() after
There might be a race condition -- if the moveTo triggers the update function then you don't want the other cursor's update to trigger you again...

Accedi per commentare.


ali amini
ali amini il 1 Ott 2020
Modificato: ali amini il 14 Mar 2023

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by