datacursormode: how to permanently turn on "make new data tip"?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello! I want to select multiple data points on figure using data cursor (shift + click). Can this functionality be turned on programmatically in a way that there is no need for holding shift? Thank you for any advice!
1 commentaire
Adam
le 14 Nov 2017
Not that I am aware of.
doc datacursormode
gives details of what you can change programmatically on the datacursormode object, but this is not one of the things and I don't imagine it would be anywhere else. It may be possible with underlying java programming, but I wouldn't have a clue about that!
Réponse acceptée
Yair Altman
le 15 Nov 2017
"You place data tips only by clicking data objects on graphs. You cannot place them programmatically (by executing code to position a data cursor)."
This is in fact WRONG AND MISLEADING, as I explained far back in 2011: https://undocumentedmatlab.com/blog/controlling-plot-data-tips
The general solution for your specific request:
1. First, set the plot line's button-down function to a custom callback function:
hLine = plot(...);
set(hLine, 'ButtonDownFcn', @lineClickedCallback);
2. Next, implement this callback function that will add the requested data-tip at the clicked location:
function lineClickedCallback(hLine, eventData)
% Get the clicked position from the event-data
pos = eventData.IntersectionPoint;
% Get the line's containing figure
hFig = ancestor(hLine,'figure');
% Get the figure's datacursormode object
cursorMode = datacursormode(hFig);
% Create a new data-tip at the clicked location
hDatatip = cursorMode.createDatatip(hLine);
set(hDatatip, 'Position',pos, 'MarkerSize',5, 'MarkerFaceColor','none', 'MarkerEdgeColor','r', 'Marker','o', 'HitTest','off');
end
You can modify this code to make the data-tip and/or marker look different.
2 commentaires
Yair Altman
le 19 Nov 2017
This is an altogether different question so you should accept the answer on this thread (if as you said it answered it), and then open a new thread for this new question (with an appropriate title and description).
In the new question, if you make your code simpler, it is more likely to be answered: People answer questions on this forum in their spare time and don't typically have time to read lengthy codes posted by others.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Object Programming dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!