Jeff Abrahamson on 5 May 2004 13:44:02 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] gnuplot


On Tue, May 04, 2004 at 04:52:51PM -0400, Jason M. Lenthe wrote:
>   [24 lines, 67 words, 564 characters]  Top characters:_ til\nosu
> 
> 
> > If you got a solution to this, could you post it?
> 
> 
> awk makes quick work of this:
> 
> $ cat datafile
> 10 10 200
> 10 15 300
> 5 20 100
> 5 40 50
> $ awk '$3>150' datafile > data1
> $ awk '$3<=150' datafile > data2
> 
> Then in gnuplot just 
>   splot 'data1', 'data2'

Thanks.

My task was, in fact, infinitesimally harder than that, as my data was
in matrix form:

    1 1 1 1 4 1 1 1 1
    3 3 3 1 1 1 1 2 1
    2 2 2 2 2 2 2 2 2
    1 1 1 1 4 1 1 1 1
    1 1 1 1 9 1 1 1 1
    2 2 2 2 2 2 2 2 2

which in gnuplot I can display thus:

    splot 'data-file' matrix

so I'd have to do something perl-ish more like this:

    local $/ = undef;
    my($i,$j) = (0, 0);
    my @rows = <>;    # slurp
    for my $row (@rows) {
        my @elts = split(/\s+/, $row);
	$j = 0;
        for my $z (@elts) {
	    $fh1->print("$i $j $z\n") if($z < z0);
	    $fh2->print("$i $j $z\n") if($z >= z0);
	    $j++;
        }
	$i++;
    }

I haven't tested that, I probably forgot something.  And, of course,
you'd have to open the two FileHandle's.

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B

 A cool book of games, highly worth checking out:
 http://www.amazon.com/exec/obidos/ASIN/1931686963/purple-20

Attachment: signature.asc
Description: Digital signature