Copying selected lines to new figure?

44 views (last 30 days)
I have a rather large number of data plots in several figures, collected together for ease of visual comparison, but I'd like to be able to pull one or several out at a time and copy them to a separate figure. For example the currently displayed ones only! (I can access the figure data to extract all lines, but I don't know how to point only at those that are currently displayed on the plot, and with several thousand, though usually only 10 or 20 displayed at a time, it gets time consuming).
In the past I've copied the whole figure and manually deleted all other lines, but this is extremely inefficient.
I had a hunt around but didn't see any tools for extracting plotted lines from figures to new figures and/or cell arrays directly though I'm guessing there is one out there? While I imagine its not that difficult, I've had problems in the past getting the data from figure, usually because I run into handle issues that I'm not quite capable of dealing with.

Accepted Answer

Walter Roberson
Walter Roberson on 13 Aug 2013
I am not sure how you are controlling which plots are visible or not ?
Generally speaking, if an object's Visible property is 'on', and the same is true for all of its parents, then the object will be part of a figure (unless the object is currently hidden behind something else.)
If you are intending to refer to the objects that are visible by virtue of not being visibly covered up by something else, then the determination can be rather complex... especially if you are dealing with transparency.
  4 Comments
Shawn
Shawn on 13 Aug 2013
Great, thanks! I was momentarily confused because the findobj was also finding the axes themselves, and getting unhappy when copying, but I just added a line to it. Using the code below does what I want, not sure if its a bit clunky but it works for what I need.
currax = gca; %get the current axes (ie the plot to copy)
h1 = figure; % create a new figure/axes
ax1 = axes;
copyobj( findobj(currax, 'visible', 'on','type','line'), ax1 );

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!