Angharad 
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.