RE: Help with DateListPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg82215] RE: [mg82179] Help with DateListPlot
- From: "David Annetts" <davidannetts at aapt.net.au>
- Date: Mon, 15 Oct 2007 01:23:02 -0400 (EDT)
- References: <200710141008.GAA25595@smc.vnet.net>
Hi, > How do you use the DateList Plot function when you have a > 3-vector database. The first column is the date, the second > column contains the names, and the last column contains the > returns. I know that you have to use a loop.The data looks like this: > Date Item return > 1/2/01 TBill 0.67 > 1/3/01 SP 0.78 > 1/4/01 inv 0.5 > 1/5/01 inve 0.6 It's straightforward(ish). Here is one way. 1. Read the file as a Table. data = Rest@Import["d:/Tmpfiles/test.txt", "Table"] 2. Filter to dates & values date = data[[All, 1]] item = data[[All, 2]] value = data[[All, 3]] 3. Convert your dates to the format required by DateListPlot cdate[str_, base_: 2000] := Module[ {dy, mo, yr}, {dy, mo, yr} = ToExpression@StringSplit[str, "/"]; {yr + base, mo, dy} ] 4. Plot your data DateListPlot[Transpose[{cdate[#] & /@ date, value}]] You can combine steps 1 & 2 as {date, item, value} = Transpose@Rest@Import["d:/Tmpfiles/test.txt", "Table"] No loops in sight. Regards, Dave.
- References:
- Help with DateListPlot
- From: KTugbawa@gmail.com
- Help with DateListPlot