Data Cursor Position Issue

5 次查看(过去 30 天)
Conor
Conor 2011-6-20
I have a number of bar charts in a figure window and each has the datacursormode enabled. When I click on a bar with a negative value, a y position of 0 is returned. It seems to work fine for bars of positive values so I'm somewhat perplexed.
  2 个评论
Richard
Richard 2011-6-20
A simple example ( bar(-5:5) ) works OK for me. Do you have some code that reproduces the problem? Also, which version are you using?
Conor
Conor 2011-6-28
Im using 7.4.0
main program goes through a complex set of calculations to determine values to plot and calls the function below.
function BarPlots(Radii, RDI,...)
global H; %H is a global variable containing handles to multiple uicontrols and plots in a gui
...
H.hRDI=subplot('position',[3/6 b+h/2.5 w h/1.575]);% b w h]);
bar(Radii,RDI)
% After main progam has run, using the Data Cursor tool and clicking on a
% plot triggers this callback function
function CT = DataCursorClick(empty,eventdata)
global H;
set(H.hContourPlot,'fill','on')
P = get(eventdata,'Position');
T = get(eventdata,'Target');
G = get(T,'Parent');
if % structure to determine which axes has been clicked on
...
elseif G == H.hRDI
CT = {['Radius: ',num2str(P(1))],['RDI: ',num2str(P(2))]};
elseif
...
end
The problem seems to be coming from
P = get(eventdata,'Position');
When the y value, P(2) is negative on the bar plot, 0 is returned for P(2).
Thanks for the help!!

请先登录,再进行评论。

采纳的回答

Richard
Richard 2011-8-3
Conor, sorry for the delay, I didn't notice your comment until today.
This is a bug in older versions of MATLAB. I can see the issue in v7.4 for a simple bar chart with a standard data cursor:
bar(-5:5)
For all of the bars, the data cursor is being placed at the maximum Y value instead of at the maximum absolute Y value, and for negative bars this is always 0 instead of being -5, -4, -3 etc. This incorrect value is also passed into your custom datatip function. There is no easy way to directly get the correct Y (RDI) value, however you could look up the X (Radii) value in the target's XData and then use the corresponding YData value:
xd = get(T, 'XData');
[~,idx] = min(abs(xd-P(1)));
yd = get(T, 'YData');
ThisRDI = yd(idx);
This bug has been fixed in a more recent version of MATLAB - I believe from R2008b onwards, so upgrading is another option.
  1 个评论
Conor
Conor 2011-8-4
Thanks Richard
I did end up using the XData and YData of the plots to display the correct value. Only issue with that is the actual data cursor remians at the 0 location for negative bars. I haven't played with it in a few weeks now, but I'll try changing the data cursors position in the callback next.
Thanks again!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by