Imager::Heatmap makes pretty pictures, but what if we want to only use it to generate its data, then render it to an animated GIF using PDL instead of Imager? Uses a modified, broadcasting version of Heatmap in PDL to make heatmaps, and PDL animation of bouncing ball to write.
use strict; use warnings; use Imager::Heatmap; use PDL; my @insert = sample_data(); $| = 1; print "Generating GIF frame "; my %size = (xsize => 300, ysize => 300); my $t0 = time; my @hms = map { my $h = Imager::Heatmap->new(%size, xsigma => $_, ysigma => $_); $h->insert_datas(@insert); print "."; $h; } 1..90; print " time now=", time - $t0; my $all_vals = pdl map $_->matrix, @hms; # broadcasting version of Imager::Heatmap::draw use PDL::Graphics::ColorSpace; my $frame_max = $all_vals->maxover; $all_vals /= $frame_max->dummy(0); # dims: x*y frame my $hue = (1 - $all_vals)*240; my $d = cat($hue, pdl(1), pdl(1))->mv(-1,0); # dims: hsv x*y frame my $all_hms = (hsv_to_rgb($d) * 255)->byte # rgb x*y frame ->splitdim(1,300); # rgb x y frame # Imager::write_multi $all_hms->wmpeg('heatmapb.gif'); print " and now=", time - $t0, "\n"; sub sample_data { my @insert = (); while (<DATA>) { chomp; push @insert, [ split /\s+/ ] } return @insert } __DATA__ ...

In reply to Re: Animated Heatmap by etj
in thread Animated Heatmap by Anonymous Monk

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.