MathGroup Archive 2007

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

Search the Archive

Re: Re: graphing with dates and values

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73138] Re: [mg73108] Re: graphing with dates and values
  • From: Stern <nycstern at gmail.com>
  • Date: Sun, 4 Feb 2007 07:37:23 -0500 (EST)
  • References: <epv3it$96f$1@smc.vnet.net> <200702030940.EAA06059@smc.vnet.net>

The solutions offered by Dimitris and Valeri will work, but if I
understand them, they don't properly handle the cases where the dates
are at uneven intervals, and they will produce messy graphs if you
have a lot of data.

I am constantly dealing with lists that look like "freffur"'s. I'll
try to sumarize a solution; ask on the list for more details if
needed.

1. convert all the dates to what I call "Mathematica Integer" format
(which express a date as an absolute number of seconds since the
beginning of January 1,1900.) Sample code for this appears below; it
converts "1/1/2000" to 3155673600.

FromDate[Flatten[Append[RotateRight[ToExpression["{" <> StringReplace["
        1/1/2000", {"/" -> ","}] <> "}"], 1], {0, 0, 0}]]]

You'll want to save the list of "conventionally" formatted dates for
use as ticks on the x-axis, or else you'll have to convert the
Mathematica Integers back.

2. Do your listplot with the Mathematica Integers as the first member
of each pair (so {3155673600, 2.7} rather than {"1/1/2000",2.7}.

3. Now you need to label your x-axis. The trick here is that (a) if
you have more than a few data points, you won't want to label the axis
for every tick, (b) you'll want to use conventional dates ("1/1/2000")
rather than the Mathematica Integers that were used in actually
generating the ListPlot.

The outline of one way to do this looks includes the following:

a. Create an indexed list that pairs your Mathematica Integer dates
with your "conventional" dates. For example,

indexedlist=MapIndexed[{First[LISTOFINTEGERDATES[[#2]]], #1} &,
LISTOFCONVENTIONALDATES]

b. Set the ticks of your listplot with the Ticks option,
Ticks -> {Table[indexedlist[[i]], {i, 1, Length[indexedlist], FREQ}], Automatic}

where FREQ is how many dates to skip between ticks.

In this step, it is important that the conventional dates in your list
be in chronological order. There are a variety of ways to sort them if
there is any risk they will be out of order.

I hope that helps. I also hope this makes it to the list; for some
reason, messages from my gmail account often seem not to appear.

Michael



On 2/3/07, Valeri Astanoff <astanoff at gmail.com> wrote:
> On 2 fév, 11:25, "fredfur" <mrmillh... at yahoo.co.uk> wrote:
> > Hi  I have a list:
> >
> > {21-Mar-86, 27.5}, {20-Mar-86, 28.25}, {19-Mar-86, 28.75}, {18-Mar-86,
> > 29.5} etc.
> >
> > how do I graph this with the dates on the x axis and the values on the
> > y axis?
> >
> > thanks
>
> Good day,
>
> I suggest this way :
>
> In[1]:=data={{"21-Mar-86", 27.5}, {"20-Mar-86", 28.25},
> {"19-Mar-86", 28.75}, {"18-Mar-86", 29.5}};
>
> In[2]:=ListPlot[data[[All,2]],PlotJoined -> True,
>   Ticks -> {Table[{i,data[[i,1]]},{i,Length[data]}],Automatic}]
>
> Out[2]= - Graphics -
>
>
> V.Astanoff
>
>


  • Prev by Date: Re: Text Function with Graphic
  • Next by Date: Re: Re: Re: Remote Kernel does nothing
  • Previous by thread: Re: graphing with dates and values
  • Next by thread: Re: graphing with dates and values