MathGroup Archive 2003

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

Search the Archive

Re: Data Plotting With Less Typing

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45335] Re: Data Plotting With Less Typing
  • From: drbob at bigfoot.com (Bobby R. Treat)
  • Date: Wed, 31 Dec 2003 03:23:41 -0500 (EST)
  • References: <bsrho9$qio$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Try this:

parse[d : {__?AtomQ}] := {Thread[ToExpression@data[[1]] -> d]}
parse[expr_] := Flatten[expr /. parse /@ data]
select[expr_] := Flatten@Position[parse@expr, True]
extract[expr_, test_] := parse[expr][[select[test]]]

Here's some data:

data = {{"a", 
    "b", "c1", "c2", "d"}, {1.64657, 3.11775, 4.4374, 8.93891, 
      1.19198}, {5.5366, 3.5689, 1.32583, 2.6293, 2.38973}, {9.03042, 9.87567,
         4.34064, 8.09357, 
      3.44279}, {5.43228, 4.7836, 8.12985, 3.94991, 2.15411}};

Here are a couple of ways to select from the data:

parse[Sin[a/b]+c1][[select[d<c2]]]
{4.94132,2.32564,5.13284,9.03664}

extract[Sin[a/b]+c1,d<c2]
{4.94132,2.32564,5.13284,9.03664}

and here are a couple of plots:

ListPlot[extract[Sin[a/b] + c1, d < c1], PlotJoined -> True]
Histogram[extract[Sin[a/b] + c1, d < c1]]

Bobby

Steve Eichblatt <steveeichblatt at yahoo.com> wrote in message news:<bsrho9$qio$1 at smc.vnet.net>...
> Hi,
> 
> I am fairly new to Mathematica, and brand new to newsgroups.
> 
> I love alot of the features of Mathematica, but some features seem 
> sorely missing, and I wonder if i am just not finding them.
> 
> In particular, for plotting data there seems to be too much typing 
> involved. I have a data table that is imported from a CSV file or 
> retrieved with the Database Access Kit and I want to make some plots.
> 
> My data looks like this
> 
> {{"a", "b", "c1", "c2", "d"},
> {1.64657, 3.11775, 4.4374, 8.93891, 1.19198},
> {5.5366,  3.5689, 1.32583, 2.6293, 2.38973},
> {9.03042, 9.87567, 4.34064, 8.09357, 3.44279},
> {5.43228, 4.7836, 8.12985, 3.94991, 2.15411},
> etc.
> }
> 
> Where the first element contains the column headers and the rest is the 
> data. Now i want to plot a histogram of, say, Sin[a/b]+c1 where d>c2 or 
> some crazy thing.
> 
> The only way i have found to do this is along the lines of 
> psn=Position[data,_?(#[[5]]>#[[4]]&)];
> and more stuff with lots of data[[psn,1]] and data[[psn,2]]
> in it, which isn't easy to type or to read.
> 
> I wrote a very simple package to reduce the required typing by using 
> StringReplace alot. It would require a command like:
> 
> ntPlot[data,"Sin[a/b]+c1","d>c2"];
> 
> I'm pretty happy with my package, but it has a few difficult flaws. 
> Before i try to fix them, I would like to know if there is already a 
> better way to do it.
> 
> Thanks in advance,
> 
> Steve Eichblatt


  • Prev by Date: Re: How to copy pattern from one expression to another?
  • Next by Date: Re: Data Plotting With Less Typing
  • Previous by thread: Re: Data Plotting With Less Typing
  • Next by thread: Re: Data Plotting With Less Typing