Thread Subject: Legend

Subject: Legend

From: Chinelo Nebo

Date: 14 Mar, 2010 15:11:26

Message: 1 of 2

I created a small M-file which works except for one tiny problem. This is the code

function [x, XT] = pfr(Ts)
xspan = [0, 7];
XT0 = [0; 350];
[x, XT] = ode45(@(x, XT) pfr1(x, XT, Ts), xspan, XT0);
[AX,L1,L2]= plotyy (x,XT(:,1),x,XT(:,2));
xlabel('Length, m');
axes(AX(1));
ylabel('Conversion');
axes(AX(2));
ylabel('Temperature, K');
set(AX,'YTickMode','auto');
legend('Temperature Profile','Conversion');
    function cprime = pfr1(x, XT, Ts)
    cprime = [2.16*10^6*exp(-5624/XT(2))*(1-XT(1)) ; -5.28*10^7*exp(-5624/XT(2))*(1-XT(1))-0.4*(Ts-XT(2))];

According to the plotyy function, the conversion XT(1) is to be plotted first, then temperature XT(2). However the Legend insists on labelling the lines the other way round with temperature first. If I write the correct legend i.e.
legend('Conversion','Temperature Profile');
the conversion line is labelled as temperature and vice versa. Can anyone explain why this is happening? Thanks

Subject: Legend

From: us

Date: 14 Mar, 2010 19:26:04

Message: 2 of 2

Chinelo Nebo
> According to the plotyy function, the conversion XT(1) is to be plotted first, then temperature XT(2). However the Legend insists on labelling the lines the other way round with temperature first. If I write the correct legend i.e.
> legend('Conversion','Temperature Profile');
> the conversion line is labelled as temperature and vice versa. Can anyone explain why this is happening? Thanks

one of the solutions
- if you do not assign the graphics handles to their respective legend,
  the order of the legend follows the stack of the handles...

% thus, use this syntax...
     x=1:10;
     [ax,lha,lhb]=plotyy(x,rand(size(x)),x,1.*x);
     set(lha,'marker','s');
     set(lhb,'marker','o');
     legend([lhb;lha],{'b','a'});

us

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
code us 14 Mar, 2010 15:29:22
graphics handle us 14 Mar, 2010 15:29:22
plotyy us 14 Mar, 2010 15:29:22
legend us 14 Mar, 2010 15:29:22
rssFeed for this Thread

Contact us at files@mathworks.com