Re: Legend for DateListPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg100038] Re: [mg100004] Legend for DateListPlot
- From: Darren Glosemeyer <darreng at wolfram.com>
- Date: Fri, 22 May 2009 01:45:58 -0400 (EDT)
- References: <200905210416.AAA10031@smc.vnet.net>
greg.mcavoy at gmail.com 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. Needs["PlotLegends`"] 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
- References:
- Legend for DateListPlot
- From: greg.mcavoy@gmail.com
- Legend for DateListPlot