Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: plot time vs date

  • To: mathgroup at smc.vnet.net
  • Subject: [mg26490] Re: [mg26461] plot time vs date
  • From: BobHanlon at aol.com
  • Date: Thu, 28 Dec 2000 02:52:28 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Use seconds for both axes and label the Ticks in the format that you want.

toStringPair[x_Integer?NonNegative] := 
    ToString[PaddedForm[x, 2, NumberPadding -> {"0", "0"}, 
        NumberSigns -> {"", ""}]];

secPerDay = 24 * 60 * 60;

months = {
      "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
      "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

startDate = {2000, 12, 1, 12, 0, 0}; (* Dec 1, 2000; 12 : 00 : 00 *)

endDate = {2000, 12, 31, 12, 0, 0}; (* Dec 31, 2000; 12 : 00 : 00 *)

xmin = FromDate[startDate]; (* seconds *)

xmax = FromDate[endDate]; (* seconds *)

ymin = 8*60*60; (* seconds in eight hours = > 8 : 00 : 00 *)

ymax = 12*60*60; (* seconds in twelve hours = > 12 : 00 : 00 *)

ystep = 10*60; (* 10 minutes *)

data = Table[{Random[ Integer, {xmin, xmax}], 
        Random[Integer, {ymin, ymax}]}, {25}];

ListPlot[data, Ticks -> {
        Join[
          Table[{x, 
              months[[#1]] <> "-" <> toStringPair[#2] & @@ 
                Rest[Drop[ToDate[x], -3]],
              {0.01, 0.}, {GrayLevel[0.], AbsoluteThickness[0.25]}}, 
            {x, xmin, xmax, 5*secPerDay}], 
          Table[{x, "",
              {0.004, 0.}, {GrayLevel[0.], AbsoluteThickness[0.125]}}, 
            {x, xmin - secPerDay, xmax + secPerDay, secPerDay}]], 
        Join[
          Table[{y, 
              #1 <> ":" <> #2 & @@ (toStringPair /@ 
                    Drop[Drop[ToDate[y], 3], -1]),
              {0.01, 0.}, {RGBC, AbsoluteThickness[0.25]}}, 
            {y, ymin, ymax, 3*ystep}], 
          Table[{y, "",
              {0.004, 0.}, {GrayLevel[0.], AbsoluteThickness[0.125]}}, 
            {y, ymin - ystep, ymax + ystep, ystep}]]}, 
    PlotStyle -> {AbsolutePointSize[3], RGBColor[1, 0, 0]}, 
    PlotRange -> {{xmin - 2*secPerDay, xmax + secPerDay}, {ymin - ystep, 
          ymax + ystep}}, 
    AxesOrigin -> {xmin - 2*secPerDay, ymin - ystep}, 
    ImageSize -> {500, 310}];


Bob Hanlon

In a message dated 12/21/00 11:24:25 PM, Maarten.vanderBurgt at icos.be writes:

>How do I make a plot with time (format hh:mm) on the ordinate and date
>(
>format MMM-dd) on the abscissa?
>


  • Prev by Date: RE: simple questions about matrices
  • Next by Date: Re: simple questions about matrices
  • Previous by thread: plot time vs date
  • Next by thread: Open Letter to Borut L.