Need to know how to put datatip in-between two indices
이전 댓글 표시
Hi all!
I'd like to add datatips to a graph of mine at locations that are not necessarily positive integer indices. The indices on the x-axis might for example be 3.14 or 1.414.
I've been using the following file so far: http://www.mathworks.com/matlabcentral/fileexchange/19877-makedatatip/content/makedatatip.m
A simple example of how to go about inserting these datatips: http://techblog.arinn.net/2013/08/programmatic-manipulation-of-datatips-in-matlab/
How to make e.g. makedatatip(ph,[1.414 3.14) work with the plot handle is an open question. I appreciate your help kindly.
댓글 수: 6
per isakson
2014년 7월 13일
편집: per isakson
2014년 7월 13일
Thanks for the link to the blog!
"the plot handle" . There is no graphic handle object named "plot" (?)
Read the blog post once more. It answers your question.
Gunnar
2014년 7월 13일
per isakson
2014년 7월 13일
편집: per isakson
2014년 7월 13일
Blog post says:
tip = find(x >= 0,1,'first'); % get the index of the first x => 0
makedatatip(ph,[tip]) % use the handle and the index to place the datatip
Thus, the second argument of makedatatip is an index (or possibly an array of indicies).
plot returns handles of line objects.
>> ph = plot( 1:12)
ph =
223.0016
>> get( ph, 'Type' )
ans =
line
Gunnar
2014년 7월 13일
per isakson
2014년 7월 13일
AFAIK: "between two indices" . It is not possible.
dpb
2014년 7월 13일
Indeed, w/ the code as given it isn't...inside we find the following--
...
X = get(hObj,'XData'); % the X,Y data for the lines of the figure
Y = get(hObj,'YData');
...
% Loop through each specified data point
for n = 1:size(index,1)
% Create position vector
...
elseif isempty(Z)
pos = [X(index(n)) Y(index(n))];
...
% Create datatip
hDatatip(n) = createDatatip(hDataCursorMgr, hObj);
...
set(hDatatip(n),'Position',pos)
So, you can see the position vector is created only from the actual datapoints in the graph by this function.
It does seem somewhat peculiar that only indices are accepted as the arguments; looks like to use it for numeric data you'll have to first do a find on the figure datapoints to return the nearest point(s) to the location you'd like to locate the datatip but as Per says (and the code above verifies) it's going to have to be at that index, not at some arbitrary [x,y] position.
I don't have any idea what the actual abilities are within the object createDatatip creates are; whether it also has a way to set a location based on the x,y coordinates of the axes object as well as at a particular index altho one would assume the latter translates to the former but whether its exposed or not would be the key...
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!