#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;
# Prepare data to plot
my @x = (1 .. 5);
my @y = ();
for (my $i = 0; $i < @x; $i++)
{
my $y = sqrt($x[$i]) + (rand()-0.5);
push(@y, $y);
}
# Chart object
my $chart = Chart::Gnuplot->new(
output => "splines.png",
xrange => [0, 6],
yrange => [0, 3],
imagesize => "0.45,0.45",
);
# DataSet object of the points
my $points = Chart::Gnuplot::DataSet->new(
xdata => \@x,
ydata => \@y,
style => "points",
color => "#DD8888",
width => 5,
);
# Join the points by splines
my $splines = $points->copy();
$splines->style("lines");
$splines->color("#88DD88");
$splines->smooth("csplines");
# Plot the graph
$chart->plot2d($splines, $points);