From: Walter Roberson <>
User-Agent: Thunderbird (Macintosh/20100228)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to add legend to an area plot with line plot overlay
References: <hsneb1$7s0$>
In-Reply-To: <hsneb1$7s0$>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 14
Message-ID: <47IHn.10680$wV.1561@newsfe11.iad>
X-Trace: newsfe11.iad 1273974336 (Sun, 16 May 2010 01:45:36 UTC)
NNTP-Posting-Date: Sun, 16 May 2010 01:45:36 UTC
Date: Sat, 15 May 2010 20:45:35 -0500
Xref: comp.soft-sys.matlab:636186

Patrick Xu wrote:
> Hi, I am trying to create a plot with an area plot and a line plot (on 
> the second axis). My question is how do you add a legend for both plots. 

When you call legend() you can specify objects whose legend is to be 
included. The legend will be positioned on the axis(es) for those 
objects, according to the parameters you specify. You would want 
different positions for the two different axes. There is no direct way 
to specify that you would like one legend to be "underneath" or "beside" 
another, but if you were to position one first then you might be able to 
  get() the legend position and work out the position from there. If I 
recall correctly, each legend box is placed on a new axis, so a figure 
that had two plots on different axis, and distinct legends for each, 
would involve a total of four axes.