in reply to Re^2: 2d contour plot using Chart::Gnuplot
in thread 2d contour plot using Chart::Gnuplot
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
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: 2d contour plot using Chart::Gnuplot
by Ppeoc (Beadle) on Mar 03, 2016 at 17:41 UTC | |
|
Re^4: 2d contour plot using Chart::Gnuplot
by Lotus1 (Vicar) on Mar 04, 2016 at 19:48 UTC | |
by poj (Abbot) on Mar 04, 2016 at 19:54 UTC | |
by Lotus1 (Vicar) on Mar 04, 2016 at 20:04 UTC |