If one imagines the first two columns as 'objects' the third column is a measure of similarity between those two objects. I want to create a 2D grid as an image (.png/.ps file or similar)
As has been said already, map the values on an array and map this array to an arbitary graphic output, like:
... use Imager; # OPEN FILE my $fn = 'datafile.dat'; open my $fh, '<', $fn or die "$fn $!"; # READ DATA INTO 2D MATRIX my @matrix = map [ qw(-1) x 40 ], 1..40; $matrix[$_->[1]][$_->[0]] = $_->[2] for map [split /\s+/ ], <$fh>; # PREPARE IMAGE my $scale=10; my $img = Imager->new(xsize=>40*$scale, ysize=>40*$scale, channels=>3 +); $img->box(filled=>1, color=>'#FFFFFF'); # CREATE IMAGE for my $row (0 .. @matrix-1) { for my $col (0 .. @{$matrix[$row]}-1) { my $val = $matrix[$row][$col]; next if $val == -1; # SELECT APPROPRIATE COLOR (BE CREATIVE HERE ;-) $img->box( color=>[ ($val/10)*25, $val*2.5, $val ], filled=>1, xmin=>$col*$scale, ymin=>$row*$scale, xmax=>($col+1)*$scale, ymax=>($row+1)*$scale ) } } # DUMP IMAGE TO FILE $img->write(file=>'my.jpg', jpegquality=>90) or die $img->errstr; ...
(This is my first shot at Imager - after sams remark - and therefore the reason that I posted this, so feel free to give hints ...)
Regards
mwa
Modification #1:
In reply to Re: matrix 'graphic' problem
by mwah
in thread matrix 'graphic' problem
by Angharad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |