Thread Subject: Finding legend handle among a figure's children

Subject: Finding legend handle among a figure's children

From: Heywood

Date: 17 Nov, 2008 13:38:02

Message: 1 of 3

Does anyone know a way to identify which of a figure's children is a legend?*

At the moment I have a plot with 4 lines in it and a legend. Then get(gca,'children') gives me those handles, while get(gcf,'children') gives me a vector of two handles (one for the legend and one for the axis). I am assuming that the first element in that vector will always point to the legend (since it makes little sense to generate a legend before there is an axis) -- but is that always the case? If not, can anyone suggest a cleaner way to do this?

Thanks in advance,

/HJ

*Obligatory: no, Lisa Marie Presley does not qualify... ;)

Subject: Finding legend handle among a figure's children

From: Doug Schwarz

Date: 17 Nov, 2008 13:56:08

Message: 2 of 3

In article <gfrs3q$6f4$1@fred.mathworks.com>,
 "Heywood " <heywoodj123@yahoo.com> wrote:

> Does anyone know a way to identify which of a figure's children is a legend?*
>
> At the moment I have a plot with 4 lines in it and a legend. Then
> get(gca,'children') gives me those handles, while get(gcf,'children') gives
> me a vector of two handles (one for the legend and one for the axis). I am
> assuming that the first element in that vector will always point to the
> legend (since it makes little sense to generate a legend before there is an
> axis) -- but is that always the case? If not, can anyone suggest a cleaner
> way to do this?
>
> Thanks in advance,
>
> /HJ
>
> *Obligatory: no, Lisa Marie Presley does not qualify... ;)

The legend will have its Tag property set to 'legend' so

  findobj(gcf,'Type','axes','Tag','legend')

should be pretty safe.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: Finding legend handle among a figure's children

From: Heywood

Date: 17 Nov, 2008 15:59:02

Message: 3 of 3

Doug Schwarz <see@sig.for.address.edu> wrote ...

> The legend will have its Tag property set to 'legend' so
>
> findobj(gcf,'Type','axes','Tag','legend')
>
> should be pretty safe.

Thanks Doug! That's s exactly what I was looking for.

Cheers,

/HJ

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
legend Heywood 17 Nov, 2008 08:40:23
handle Heywood 17 Nov, 2008 08:40:23
figure Heywood 17 Nov, 2008 08:40:23
rssFeed for this Thread

Contact us at files@mathworks.com