#!/usr/bin/perl -w use strict; use Chart::Gnuplot; # Data my $numX = 20; my $numY = 20; my (@x, @y, @z) = (); for (my $i = 0; $i <= $numX; $i++) { my $x = 10*($i/$numX - 0.5); # $x ranges from -5 to +5 for (my $j = 0; $j < $numY; $j++) { my $y = 10*($j/$numY - 0.5); # $y ranges from -5 to +5 my $z = $x*$x - 2*$y*$y; $x[$i][$j] = $x; $y[$i][$j] = $y; $z[$i][$j] = $z; } } # Create chart object my $chart = Chart::Gnuplot->new( output => "plot3d_3.png", title => "3D surface plot from arrays of x, y and z corrdinates", ); # Create dataSet object my $dataSet = Chart::Gnuplot::DataSet->new( xdata => \@x, ydata => \@y, zdata => \@z, style => 'lines', ); # Plot the graph $chart->plot3d($dataSet);