[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Clone axes
From: |
Ben Abbott |
Subject: |
Re: Clone axes |
Date: |
Mon, 17 Oct 2011 10:00:54 -0400 |
On Oct 17, 2011, at 9:32 AM, pantxo diribarne wrote:
> I2011/10/17 Ben Abbott <address@hidden>
> On Oct 17, 2011, at 8:12 AM, pantxo diribarne wrote:
>
> > 2011/10/17 Ben Abbott <address@hidden>
> >
> >> On Oct 17, 2011, at 5:46 AM, pantxo diribarne wrote:
> >>
> >> > Hello list ;
> >> >
> >> > I would like to know if there is a way to clone an axes of a multiple
> >> > axes figure into an other figure. Suppose I have made a first figure
> >> > that way :
> >> >
> >> > figure(1)
> >> > subplot(2,1,1);
> >> > contourf(rand(10,10));
> >> > subplot(2,1,2);
> >> > plot(1:10);
> >> >
> >> > ... and I would like to clone the subplot(2,1,1) axes into another
> >> > figure. Is there a way to do that?
> >> >
> >> > Pantxo
> >>
> >> Matlab has a functioned named copyobj() that does this. Unfortunately,
> >> this is not yet supported by Octave.
> >>
> >> If you a interesting in writing an equivalent function for Octave, you can
> >> ask for advice / assistance on the maintainer's email list.
> >>
> >> Ben
> >
> > That is indeed what I am looking for, but I don't have a clue on the way it
> > should be written. I'll have to understand the way graphic object are built
> > and see if I am able to write such function. Do you have an advice on the
> > functions I should read and understand.
> >
> > Pantxo
>
> Each graphics object has a set of properties that provides sufficient
> information to recreate it. To make a copy you'll need to ...
>
> (1) If the object is an axes, make the figure it is to be copied to
> "current". If the object is a descendant of an axes, make the axes which is
> to be the copies ancestor current.
> (2) Create a new object of the "type" being copied.
> (3) Copy the values of the properties that are both writable and have been
> manually defined.
>
> best to handle hggroups.
>
> Ben
>
>
> I tried to do something like this but I obviously miss something (probably
> many). The following produces an empty plot
>
> ##create first figure
> figure(1)
> subplot(2,1,1);
> contour(rand(10,10));
> subplot(2,1,2);
> plot(1:10);
>
>
> hg1 = findobj (gcf, "type","hggroup")
> hg_struct = get(hg1);
>
> #create the second for clone copy
> figure(2);
>
> ax_hdl = axes("parent",gcf); #new axes
> hg2 = hggroup (ax_hdl); #new hggroup
> fields = fieldnames (hg_struct); #fields to copy
> lg = length(fields);
> #raw copy
> for ii = 1:lg
> prop = fields{ii};
> hg2_struct = get(hg2);
> if strcmp(prop, "children")
> #for patches
> elseif strcmp(prop, "type")
> #
> elseif strcmp(prop, "uicontextmenu")
> #
> else
> temp = get (hg1, prop);
> if isfield(hg2_struct, prop)
> set(hg2, prop, temp);
> else
> addproperty (prop, hg2,"any" ,temp)
> set(hg2, prop, temp);
> endif
> clear temp
> endif
> endfor
>
> Pantxo
Just a quick response to say I'll eventually get back to this, but have hectic
schedule this week. I may be able to look at this later today, or it may be a
week for before I have the time.
If someone else would like to help Pantxo with this, please do.
Ben