Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to remove a single plot from existing axes?

Tags:

plot

axes

matlab

Is there an easy way to remove a plotted line from a set of axes without clearing everything else on the axes? I'm trying to implement a GUI with a listbox containing several data sets. I can make the callback function plot the selected data, but I'm not sure how to 'unplot' it when I deselect a data set. Any ideas?

like image 675
Doresoom Avatar asked Aug 02 '10 14:08

Doresoom


1 Answers

If you save a handle to the created graphics object, you can call DELETE on it to remove it from the plot:

hLine = plot(...);  %# Create a line with PLOT
delete(hLine);      %# ...and delete it

Alternatively, if you didn't save the handle in a variable, you can search for it using FINDOBJ, then delete it when you find it.

If you don't actually want to delete it, but simply turn the visibility of the line on and off, you can set the 'Visible' property of the graphics object accordingly:

set(hLine,'Visible','off');  %# Make it invisible
set(hLine,'Visible','on');   %# Make it visible
like image 67
gnovice Avatar answered Sep 21 '22 16:09

gnovice