I can get a heat-mappy looking output file using the following:

use strict; use warnings; use Chart::Gnuplot; my @data = ( [0, 0, 10], [0, 1, 10], [0, 2, 10], [], [1, 0, 10], [1, 1, 5], [1, 2, 10], [], [2, 0, 10], [2, 1, 1], [2, 2, 10], [], [3, 0, 10], [3, 1, 0], [3, 2, 10], ); my $chart = Chart::Gnuplot->new( output => "test1.png", title => "3D plot from arrays of x, y and z coordinates", xlabel => 'x', ylabel => 'y', ); $chart->set(pm3d => 'map'); $chart->set(palette => 'defined (0 0 0 1, 1 1 1 0, 2 1 0 0)'); my $dataSet = Chart::Gnuplot::DataSet->new( points => \@data, ); $chart->plot3d($dataSet);

But it doesn't represent the data. I had to put in the []'s to prevent the following warning:

Warning: Single isoline (scan) is not enough for a pm3d plot. Hint: Missing blank lines in the data file? See 'help pm3d' + and FAQ.

So the problem seems to be with the passing of the dataset rather than setting any pm3d options. I also tried passing a datafile in the data grid format (i.e. with blank lines between blocks), but got the same warning, which seems to indicate that Chart::Gnuplot is helpfully stripping out blank lines from datafiles as well as comments (I haven't checked the source). Not sure where to go from here, but it seems to be doable if the dataset data can be put into the right format

UPDATE

I think the above approach is working, it's just the dataset was too small to demonstrate it. If I replace the 'Valley of the Gnu' data with a 10,000 point generated dataset in the same format, it all works wonderfully. Also added some contour lines to the plot:

use strict; use warnings; use Chart::Gnuplot; my @data = (); for my $x (0..100) { for my $y (0..100) { push @data, [$x / 10, $y / 10, ($x**2 - $y**2) / 100]; } push @data, []; # need an empty arrayref between blocks to simulate +a newline } my $chart = Chart::Gnuplot->new( output => "test1.png", title => "3D plot from arrays of x, y and z coordinates", xlabel => 'x', ylabel => 'y', ); $chart->set(pm3d => 'map'); $chart->set(palette => 'defined (0 0 0 1, 1 1 1 0, 2 1 0 0)'); $chart->set(contour => 'base'); my $dataSet = Chart::Gnuplot::DataSet->new( points => \@data, ); $chart->plot3d($dataSet);

In reply to Re^3: 2d contour plot using Chart::Gnuplot by Myrddin Wyllt
in thread 2d contour plot using Chart::Gnuplot by Ppeoc

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.