Thread Subject: Add to a subplot

Subject: Add to a subplot

From: Aaron Fude

Date: 18 Sep, 2008 22:30:37

Message: 1 of 5

Hi,

The subplot help states that invoking subplot(m, n, p) deletes the
contents and I have found myself unable to add to a subplot without
deleting the contents. How does one do it? (E.g. on a figure that was
obtained with the help of an open() command.)

Thanks,

Aaron

Subject: Add to a subplot

From: Walter Roberson

Date: 18 Sep, 2008 23:16:55

Message: 2 of 5

Aaron Fude wrote:
 
> The subplot help states that invoking subplot(m, n, p) deletes the
> contents and I have found myself unable to add to a subplot without
> deleting the contents. How does one do it?

>> help subplot

    If a SUBPLOT specification causes a new axis to overlap an
    existing axis, the existing axis is deleted - unless the position
    of the new and existing axis are identical. For example,
    the statement SUBPLOT(1,2,1) deletes all existing axes overlapping
    the left side of the Figure window and creates a new axis on that
    side - unless there is an axes there with a position that exactly
    matches the position of the new axes (and 'replace' was not specified),
    in which case all other overlapping axes will be deleted and the
    matching axes will become the current axes.

> (E.g. on a figure that was
> obtained with the help of an open() command.)

>> help subplot

    SUBPLOT('position',[left bottom width height]) creates an
    axis at the specified position in normalized coordinates (in
    in the range from 0.0 to 1.0).

So if you have an existing axis that you want to match the position of,
you can get() and record the Units of that existing axes, set() the Units to
'normalized', get() and record the Position of the existing axes,
set() the Units of the existing axes back to the recorded Units. The
recorded position could then be passed to subplot(). On the other hand,
doing that would just amount to doing the same thing as using axes() to
make the existing axes the "current" axes.

So... why not just findobj(TheFigureHandle, 'Type', 'axes') or something
similar to find the -existing- axes, and make that existing axes the
current axes ??

Subject: Add to a subplot

From: Aaron Fude

Date: 18 Sep, 2008 23:32:25

Message: 3 of 5

On Sep 18, 7:16=A0pm, Walter Roberson <rober...@hushmail.com> wrote:
> Aaron Fude wrote:
> > The subplot help states that invoking subplot(m, n, p) deletes the
> > contents and I have found myself unable to add to a subplot without
> > deleting the contents. How does one do it?
> >> help subplot
>
> =A0 =A0 If a SUBPLOT specification causes a new axis to overlap an
> =A0 =A0 existing axis, the existing axis is deleted - unless the position
> =A0 =A0 of the new and existing axis are identical. =A0For example,
> =A0 =A0 the statement SUBPLOT(1,2,1) deletes all existing axes overlappin=
g
> =A0 =A0 the left side of the Figure window and creates a new axis on that
> =A0 =A0 side - unless there is an axes there with a position that exactly
> =A0 =A0 matches the position of the new axes (and 'replace' was not speci=
fied),
> =A0 =A0 in which case all other overlapping axes will be deleted and the
> =A0 =A0 matching axes will become the current axes.
>
> > =A0(E.g. on a figure that was
> > obtained with the help of an open() command.)
> >> help subplot
>
> =A0 =A0 SUBPLOT('position',[left bottom width height]) creates an
> =A0 =A0 axis at the specified position in normalized coordinates (in
> =A0 =A0 in the range from 0.0 to 1.0).
>
> So if you have an existing axis that you want to match the position of,
> you can get() and record the Units of that existing axes, set() the Units=
 to
> 'normalized', get() and record the Position of the existing axes,
> set() the Units of the existing axes back to the recorded Units. The
> recorded position could then be passed to subplot(). On the other hand,
> doing that would just amount to doing the same thing as using axes() to
> make the existing axes the "current" axes.
>
> So... why not just findobj(TheFigureHandle, 'Type', 'axes') or something
> similar to find the -existing- axes, and make that existing axes the
> current axes ??

How do you get the existing axis from a particular subplot? Not sure
what to call get() on. And then how do you make the obtained axes the
current axes? I know how to get them but not how to set them.

Subject: Add to a subplot

From: Scott Seidman

Date: 18 Sep, 2008 23:52:26

Message: 4 of 5

Aaron Fude <aaronfude@gmail.com> wrote in news:bf4db45e-1a07-4cfd-a7a2-
761bb080180f@d45g2000hsc.googlegroups.com:

> How do you get the existing axis from a particular subplot? Not sure
> what to call get() on. And then how do you make the obtained axes the
> current axes? I know how to get them but not how to set them.

You keep track of things before its too late!!

h = subplot(...)

returns the handle of the axes of the subplot when its created. Handle
graphics, in general, is just a matter of bookkeeping.


Other than that, you'd need to use Findobj on the figure to pull out all
the axes, and then figure out somehow (by position maybe??) what handle
matches what axes.

--
Scott
Reverse name to reply

Subject: Add to a subplot

From: ControlTheoryPro@gmail.com

Date: 19 Sep, 2008 05:16:41

Message: 5 of 5

If you are opening a figure that already exists and you need to add
another subplot then I think you will need to actually create another
figure. In the new figure you will want to copy the data from the old
figure to a new subplot on the figure.

When you open up the old figure then you can use gca to get the handle
to the 1 axis on the figure (assuming there is only 1). If there are
more than one you will need to use a = get(gcf, 'children'). The
variable a will get all the children of the figure and some of those
children will be of "Type" axes. Once you get the handle to desired
axis you can use get(h, 'children') where h is the handle to that
desired axis.

The plotted data will be children of the desired axis and most likely
of the type "line". The XData, YData, and ZData properties of the
line object will have the data necessary for replotting on the new
figure and new subplot. Then you can add data the subplots you are
adding.

Gabe
The MATLAB category of my Control Systems wiki:
http://wikis.controltheorypro.com/index.php?title=Category:MATLAB

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com