datacursormode: how to permanently turn on "make new data tip"?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Marko Usaj
el 14 de Nov. de 2017
Comentada: Yair Altman
el 19 de Nov. de 2017
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 comentario
Adam
el 14 de Nov. de 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!
Respuesta aceptada
Yair Altman
el 15 de Nov. de 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 comentarios
Yair Altman
el 19 de Nov. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Object Programming en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!