How to Delete Scatter Plot Points From a Figure in Matlab

It is often useful to update the location of scatter plot points overlaid on a Matlab figure, especially when displaying the incremental results of iterative algorithms. In order to do this, the existing scatter plot points need to be deleted prior to redrawing new scatter points.

In order to delete points which have been plotted on an axis with scatter(), the following code can be used:

delete(findobj(gca, 'type', 'patch'));

It is not immediately obvious from the documentation, but scatter points are considered to be a “patch” type object. Thus, this line of code finds all patch objects on the current axes and deletes them.

To delete the 2D lines drawn by Matlab’s plot() function a similar statement can be used, in this case by changing the type to the more obvious value of “line”:

delete(findobj(gca, 'type', 'line'));

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">