Thread Subject: Reorder legend entires

Subject: Reorder legend entires

From: Stefan

Date: 16 Nov, 2007 10:59:17

Message: 1 of 11

Hi

Is it possible to reorder legend entries via the GUI figure
proprety editor?

Reorder in the sense of with data set is top, which second,
and so forth within the legend box.

Thanks!
Stefan

Subject: Reorder legend entires

From: Stefan

Date: 22 Nov, 2007 12:10:24

Message: 2 of 11

Is this problem too silly or is there really no way...?


Subject: Reorder legend entires

From: Bruno Luong

Date: 22 Nov, 2007 13:38:40

Message: 3 of 11

"Stefan " <stefan.vonbergen.nospam@aerodynamics.ch> wrote in
message <fi3rjg$o6n$1@fred.mathworks.com>...
> Is this problem too silly or is there really no way...?
>
>

Not sure what this is what you like


h=plot(rand(20,3));
c={'plot 1' 'plot 2' 'plot 3'}; % legend list
order=[2 3 1];
legend(h(order),c{order});

Bruno

PS: Isn't just me ? Most of the time it's really difficult
to me to understand many posts in this forum.


Subject: Reorder legend entires

From: Stefan

Date: 22 Nov, 2007 13:48:53

Message: 4 of 11

Basically yes, but I want to do it in the figure editor, by
clicking instead of coding.

Subject: Reorder legend entires

From: Praveen Prasanna

Date: 21 Dec, 2007 16:57:44

Message: 5 of 11

Stefan,
This is not a silly question. I wanted to do the same
thing and found your post. Bruno, suggested a solutions
using coding. I didn't try it, but in general if you can
code a solution, you can make the same changes in the
Graphical User Interface.

In order to change the coding.
1) Click the arrow button so that you can select objects in
the figure.

2) Then select your legend, so that the bottom panel opens
up.

3) Select the inspector radio button.

4) In the list, scroll down to "String". You will see a
yellow figure with [1xn cell array].

5) Click on the yellow figure and another window will open
with the elements of your legend. Now you can change the
names and it will change the order appropriately.

This worked for me properly, I hope it does for you also.

Praveen

P.S. Bruno play nice.

Subject: Reorder legend entires

From: Bruno Luong

Date: 21 Dec, 2007 18:39:18

Message: 6 of 11

"Praveen Prasanna" <pprasa@comcast.net> wrote in message
<fkgra8$17p$1@fred.mathworks.com>...

>
> P.S. Bruno play nice.

Should I take it as a compliment? Thank you.

Happy holidays to you all.

Bruno

Subject: Reorder legend entires

From: Stefan

Date: 11 Jan, 2008 14:21:02

Message: 7 of 11

Well ok, I can Praveen's points. But what I can do in this
dialog is just rename the lines (which can be done directly
by double clicking into the legend).

But I didn't manage to reorder the legends, like set the
third legend entry on top and so on.

Happy New Year to everyone!

Cheers
Stefan

Subject: Reorder legend entires

From: Praveen Prasanna

Date: 27 Feb, 2008 05:06:15

Message: 8 of 11

"Stefan " <stefan.vonbergen.nospam@aerodynamics.ch> wrote
in message <fm7u0e$3h1$1@fred.mathworks.com>...
> Well ok, I can Praveen's points. But what I can do in this
> dialog is just rename the lines (which can be done
directly
> by double clicking into the legend).
>
> But I didn't manage to reorder the legends, like set the
> third legend entry on top and so on.
>
> Happy New Year to everyone!
>
> Cheers
> Stefan
>


When I did this on my computer, I actually changed the
order of the legend items.

Subject: Reorder legend entires

From: framboise L

Date: 14 Aug, 2008 23:28:16

Message: 9 of 11

You may try this trick

-Delete data
-Undo delete
And the data will fall to the last place in the legend

Still waiting for an better way to do it...

Subject: Reorder legend entires

From: Steven Lord

Date: 15 Aug, 2008 02:13:13

Message: 10 of 11


"framboise L" <francoise.lepine.1@ulaval.ca> wrote in message
news:g82f2g$9n5$1@fred.mathworks.com...
> You may try this trick
>
> -Delete data
> -Undo delete
> And the data will fall to the last place in the legend
>
> Still waiting for an better way to do it...

% Sample data
x = 1:10;

% Handles storage
h = zeros(5, 1);

% Set up the axes
axis([0 11 0 51]);
hold on;

% Set up the colors
colors = {'r', 'g', 'b', 'y', 'k'};

% Plot the five lines and store their handles in h
for k = 1:5
    h(k) = plot(x, k*x, colors{k});
end

% Create the default legend and wait for you to press a key
legend({'one','two','three', 'four', 'five'})
pause

% Flip the order in which the lines are associated with the labels and again
wait for you to press a key
legend(flipud(h), {'one', 'two', 'three', 'four', 'five'})
pause

% Randomly shuffle the ordering of the lines every 0.1 second
for k = 1:10
    legend(h(randperm(5)), {'one', 'two', 'three', 'four', 'five'});
    pause(0.1);
end

--
Steve Lord
slord@mathworks.com


Subject: Reorder legend entires

From: sam p

Date: 13 Jan, 2009 06:17:01

Message: 11 of 11

for the gui, haven't found anything better than the delete method posted by framboise L.

for coding, the legend command takes a list of handles for each data series, and then a string corresponding to each.

if you just have a .fig you want to edit, you can get the handles by:

% get the figure handle
h = figure(1) % or whatever fig
% get the axes handle
a = get(h, 'CurrentAxes')
% get the handles for children of the axes -- these are the data series handles
c = get(a, 'Children')
% generate a legend command using these "children"
legend(c([1 3 5]), 'label for data 1', 'label for 3', 'label for 5')

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
reorder legend Stefan 16 Nov, 2007 06:00:02
rssFeed for this Thread

Contact us at files@mathworks.com