in reply to Re: 2d contour plot using Chart::Gnuplot
in thread 2d contour plot using Chart::Gnuplot

Thanks for your help. This isn't what I am looking for. From the little research I did, it requires the use of pm3d. Instead of the points, I am looking for a rgb colorscale plot, i.e more like a heatmap
  • Comment on Re^2: 2d contour plot using Chart::Gnuplot

Replies are listed 'Best First'.
Re^3: 2d contour plot using Chart::Gnuplot
by BrowserUk (Patriarch) on Mar 02, 2016 at 22:44 UTC

    Can you achieve the plot you're after when using gnuplot directly?

    If not, then you should probably start by doing that; and seek out some gnuplot expertise to help; and then come back to the Perl interface later. On past experience, there's not much of that around here.

    For my part, I have never worked out how to get gnuplot to do what I want. Like so many OSS packages, it probably contains really amazing code, but the documentation is such that the you need to dedicate years to working out the effects of combining its various obscure directives before you will be able to produce what you want from it rather than just having to accept what it decided to produce. It seems to be fine if all you want to produce is a pretty picture; but if you need that picture to be interpretable in the sense that real and accurate information can be read back from it, look elsewhere.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: 2d contour plot using Chart::Gnuplot
by Myrddin Wyllt (Hermit) on Mar 03, 2016 at 14:34 UTC

    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);
      wow! This is exactly what I was looking for! Thank you! This is beautiful :)

      I tried this on Windows 7 and I get an Invalid Parameter - 90. At first it seemed to be related to how the module calls gnuplot according to this thread. Then I found this article that explains the true problem is that Chart::Gnuplot is attempting to call ImageMagick's convert executable. On Windows convert is a utility that converts a volume from FAT32 to NTFS. To get Chart::Gnuplot working you need to install ImageMagick and Ghostscript. I haven't tried it yet but it looks promising.

        Try adding this line

        my $chart = Chart::Gnuplot->new( terminal => 'png',
        poj
Re^3: 2d contour plot using Chart::Gnuplot
by RonW (Parson) on Mar 03, 2016 at 02:10 UTC

    I am looking for a rgb colorscale plot, i.e more like a heatmap

    The gnuplot site has examples of heat maps. Probably can learn enough from those to figure out how to do it in Perl.

    There are several other gnuplot related modules available if you have trouble.

Re^3: 2d contour plot using Chart::Gnuplot
by Lotus1 (Vicar) on Mar 02, 2016 at 15:55 UTC

    If you just need rgb plotted on a 2d chart then PDL::Graphics::TriD has imagrgb which claims to do this.

    The documentation mentions imag2d which I found in PDL::Graphics2D.