datacursormode: how to permanently turn on "make new data tip"?
14 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Adam
2017 年 11 月 14 日
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!
採用された回答
Yair Altman
2017 年 11 月 15 日
"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 件のコメント
Yair Altman
2017 年 11 月 19 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Graphics Object Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!