Search code examples
matlabplotmatlab-figure

Matlab how to select markers on plot that are too small to be clicked on


I am trying to edit a figure by selecting markers to make them bigger. However, the markers are too small and are hidden below a line of best fit. Whenever I try to click on the markers, I select the line instead. How can I select the markers only?

I'm plotting using

[fitresult, gof] = fit( xData, yData, ft, opts );
h = plot( fitresult, xData, yData );

Solution

  • You can pop your marker on top with uistack(marker_obj,'top'), so that they will be drawn on top of the trend line. Downside is that the trend line will be hidden below the markers.

    Alternatively, you can can set your trend line so that it is not clickeable: set(trendline_obj,'HitTest','off'). The click will hit the next object below (marker, axes object,...). Downside is that you can't have a callback associated to clicking on the trend line. See HitTest in the documentation of Line properties

    The solution to have the line drawn on top and a callback upon clicking on the line, is to make a duplicate of the trend line. Have one copy drawn on top with HitTest='off' and another one drawn at the bottom (below the markers) with HitTest='on' and a callback. The callback will be called when clicking on portions of the line that are not covered by markers.