Data Cursor Position Issue

조회 수: 2 (최근 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에서 Bar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by