Why does the ButtonDownFcn callback of my axes object stop working after creating something?

I create a set of axes in the shape and assign a callback to my property 'ButtonDownFcn'as follows:

HRaxes = axes('Parent', Figure, 'Position', [.05 .60 .9 .35],...
              'XLimMode', 'manual', 'ButtonDownFcn', @HR_ButtonDown);

If the callback function is defined as such:

function HR_ButtonDown(hObject, eventData)
  %# Do some stuff here when the axes is clicked on...
end

The callback works fine until I draw something on the axes like this:

plot(HRaxes, data.HR_X, data.HR_Y, 'b');

After that, the callback no longer starts when I click on the axis. What is going wrong and how can I fix it?

+3
source share
2 answers

, PLOT - , , . 'NextPlot' , , , , :

  • add - .

  • replace - Reset , Position, ( cla reset).

  • replacechildren - , Reset ( cla).

'replace' , , 'ButtonDownFcn', Reset , PLOT, . :

  • 'NextPlot' 'add' ( ), 'replacechildren' ( , ) PLOT.

    HRaxes = axes('Parent', Figure, 'Position', [.05 .60 .9 .35],...
                  'XLimMode', 'manual', 'ButtonDownFcn', @HR_ButtonDown,...
                  'NextPlot', 'add');
    plot(HRaxes, data.HR_X, data.HR_Y, 'b');
    
  • (, LINE), :

    HRaxes = axes('Parent', Figure, 'Position', [.05 .60 .9 .35],...
                  'XLimMode', 'manual', 'ButtonDownFcn', @HR_ButtonDown);
    line(data.HR_X, data.HR_Y, 'Parent', HRaxes, 'Color', 'b');
    
+2

@David Snyder, , image ButtonDownFcn. axes Parent ancestor. , , ButtonDownFcn , . ,

imh = image(some_image);
set(imh,'ButtonDownFcn',@position_and_button);

function position_and_button(hObject,eventdata)
   Position = get( ancestor(hObject,'axes'), 'CurrentPoint' );
   Button = get( ancestor(hObject,'figure'), 'SelectionType' );
   %# do stuff with Position and Button
+2

All Articles