MathGroup Archive 2008

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

Search the Archive

Re: Graph by Date

  • To: mathgroup at smc.vnet.net
  • Subject: [mg93269] Re: [mg93212] Graph by Date
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 1 Nov 2008 05:13:20 -0500 (EST)
  • Reply-to: hanlonr at cox.net

mydata = {{"1/5/2004", "widgetA", 55.2},
   {"1/15/2004", "widgetD32", 5.2},
   {"2/7/2004", "no_Widgets", 34.5},
   {"5/6/2004", "widget62", 100.2},
   {"5/16/2004", "widget6", 30.5},
   {"9/13/2004", "widget 55t", 225.79}};

pts = {DateList[{#[[1]], {"Month", "Day", "Year"}}],
     #[[3]]} & /@ mydata;

DateListPlot[pts,
 Filling -> Bottom, FillingStyle -> Magenta,
 PlotStyle -> {Red, PointSize[Large]},
 PlotRange -> {{{2004, 1}, {2004, 12}}, {0, 250}},
 DateTicksFormat -> {"Month", "/", "YearShort"},
 Epilog -> (Text[#[[1]], #[[2]], {-1, -1.5}] & /@
    Transpose[{mydata[[All, 2]], pts}])]

pts = pts //. {s___, {{y_, m_, d1_, ___}, v1_}, {{y_, m_, d2_, ___}, 
      v2_}, f___} ->
    {s, {{y, m, d2, 0, 0, 0}, v1 + v2}, f};

DateListPlot[pts,
 Filling -> Bottom, FillingStyle -> Magenta,
 PlotStyle -> {Red, PointSize[Large]},
 PlotRange -> {{{2004, 1}, {2004, 12}}, {0, 250}},
 DateTicksFormat -> {"Month", "/", "YearShort"}]


Bob Hanlon

---- "Charles L. Snyder" <clsnyder at gmail.com> wrote: 

=============
Hi

Although I've searched the Mathematica documentation and this
newsgroup's files, I am having trouble producing a Plot by Month -
specifically a graph by month on the x-axis, and a total of the values
in column 3 for that month: eg.,

mydata = {{1/5/2004, "widgetA", 55.2},{1/15/2004, "widgetD32", 5.2},
{2/7/2004, "no_Widgets", 34.5},{5/6/2004, "widget62", 100.2},
{5/16/2004, "widget6", 30.5},{9/13/2004, "widget 55t", 225.79}}

result would be  a graph of
Jan 2004 57.4   (55.2+5.2)
Feb 2004 34.2
Mar 2004 0
April 2004 0
May 2004  130.7 (100.2 + 30.5)
June 2004 0
July 2004 0
Aug 2004 0
Sep 2004 225.79
all other months 0

I did find a way to summarize the dates and plot it:

data = #[[1]] & /@ mydata;
cs = Tally[Sort[data]];

DateListPlot[cs, Filling -> Bottom,
 FillingStyle -> Blue, PlotStyle -> {Red, PointSize[Large]},
 PlotRange -> {{{2004, 1}, {2004, 12}}, Automatic},
 DateTicksFormat -> {"Month", "/", "YearShort"}]

Even this gives me the error messages for the dates such as -
DateList::ambig: "Warning: the interpretation of the string \
\!\(\"10/1/2004\"\) as a date is ambiguous"

Thanks again

clsnyder


--

Bob Hanlon



  • Prev by Date: Re: Re: Hypergeometric2F1
  • Next by Date: Re: Graph by Date
  • Previous by thread: Re: Graph by Date
  • Next by thread: Re: Graph by Date