MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Legend for DateListPlot

  • To: mathgroup at
  • Subject: [mg100038] Re: [mg100004] Legend for DateListPlot
  • From: Darren Glosemeyer <darreng at>
  • Date: Fri, 22 May 2009 01:45:58 -0400 (EDT)
  • References: <>

greg.mcavoy at wrote:
> I would like to add a PlotLegend to a time series plot like the one
> below.
> DateListPlot[{Tooltip[FinancialData["MSFT", "2006"],
>    "Microsoft Corporation"],
>   Tooltip[FinancialData["SNE", "2006"], "Sony Corporation"],
>   Tooltip[FinancialData["AKAM", "2006"], "Akamai Technologies Inc"]},
>  Joined -> True]
> I tried using the PlotLegends package, but it doesn't appear to work
> with DateListPlot
> (code below)
> Needs["PlotLegends`"]
> DateListPlot[{FinancialData["MSFT", "2006"],
>   FinancialData["SNE", "2006"], FinancialData["AKAM", "2006"]},
>  Joined -> True,
>  PlotLegend -> { "Microsoft Corporation", "Sony Corporation",
>    "Akamai Technologies Inc"}]
> Is there a work around to this problem or something wrong with my
> code?  I want to export the graph to for use in a latex document so
> Tooltip is not a useful option.

The legend generation code is getting confused by the date 
specifications, and this is something we will look into fixing in a 
future version. As a workaround for now, you can convert the dates to 
AbsoluteTimes. Then the x coordinates in the data are just numbers as 
the PlotLegends code is expecting.


data = {FinancialData["MSFT", "2006"], FinancialData["SNE", "2006"],
   FinancialData["AKAM", "2006"]};

Table[data[[i, All, 1]] = Map[AbsoluteTime, data[[i, All, 1]]], {i, 3}];

DateListPlot[data, Joined -> True,
 PlotLegend -> {"Microsoft Corporation", "Sony Corporation",
   "Akamai Technologies Inc"}]

Darren Glosemeyer
Wolfram Research

  • Prev by Date: Re: A question on Grid and nested lists
  • Next by Date: Re: Rotating a list of 3D point coordinates in one shot
  • Previous by thread: Legend for DateListPlot
  • Next by thread: Re: Legend for DateListPlot