Chart-Gnuplot

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - Fix a typo in POD
    - Improve testsuite

0.07
    - Support user-specified path of the convert program
    - Support plotting parametric functions
    - Fix a bug that range does not work if axis is date/time
      (Thanks to Holyspell)

0.06
    - Support formatting legend
    - Fix an error that causes some options of one chart affects other charts
      in multiplot.
    - Fix an error in image format conversion.
    - Better support of MSWin

0.05
    - Fix a bug in timestamp option.
      (Thanks to Lou King)
    - Fix a typo in POD

MANIFEST  view on Meta::CPAN

examples/datetime_3.pl
examples/grid_1.pl
examples/grid_2.pl
examples/grid_3.pl
examples/grid_4.pl
examples/grid_5.pl
examples/grid_6.pl
examples/grid_7.pl
examples/grid_8.pl
examples/grid_9.pl
examples/legend_1.pl
examples/legend_2.pl
examples/legend_3.pl
examples/legend_4.pl
examples/legend_5.pl
examples/legend_6.pl
examples/legend_7.pl
examples/legend_8.pl
examples/legend_9.pl
examples/legend_10.pl
examples/lineStyle_1.pl
examples/lineStyle_2.pl
examples/lineStyle_3.pl
examples/lineStyle_4.pl
examples/lineStyle_5.pl
examples/multiplot_1.pl
examples/multiplot_2.pl
examples/multiplot_3.pl
examples/plot3d_1.pl
examples/plot3d_2.pl

MANIFEST  view on Meta::CPAN

t/datetime_2.gp
t/datetime.t
t/grid_1.gp
t/grid_2.gp
t/grid_3.gp
t/grid.t
t/label_1.gp
t/label_2.gp
t/label_3.gp
t/label.t
t/legend_1.gp
t/legend.t
t/lineStyle.t
t/plotAxes_1.gp
t/plotAxes.t
t/pointStyle.t
t/range_1.gp
t/range_2.gp
t/range.t
t/set_1.gp
t/set.t
t/thaw_1.dat

examples/Makefile  view on Meta::CPAN

datetime_3.png \
grid_1.png \
grid_2.png \
grid_3.png \
grid_4.png \
grid_5.png \
grid_6.png \
grid_7.png \
grid_8.png \
grid_9.png \
legend_1.png \
legend_2.png \
legend_3.png \
legend_4.png \
legend_5.png \
legend_6.png \
legend_7.png \
legend_8.png \
legend_9.png \
legend_10.png \
lineStyle_1.png \
lineStyle_2.png \
lineStyle_3.png \
lineStyle_4.png \
lineStyle_5.png \
multiplot_1.png \
multiplot_2.png \
multiplot_3.png \
plot3d_1.png \
plot3d_2.png \

examples/chartFmt_3.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

my $chart = Chart::Gnuplot->new(
    output => 'gallery/chartFmt_3.png',
);

my $data = Chart::Gnuplot::DataSet->new(
    func  => "tanh(x)",
    title => 'legend',     # legend
);

# Plot the graph
$chart->plot2d($data);

examples/legend_1.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Demonstration of formatting legend
# - show default setting

my $chart = Chart::Gnuplot->new(
    output => "gallery/legend_1.png",
);

# Lines
my $lines = Chart::Gnuplot::DataSet->new(
    func  => "cos(x)",
    title => "cosine",
);

# Points
my $points = Chart::Gnuplot::DataSet->new(

examples/legend_10.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Demonstration of formatting legend
# - composite example

my $chart = Chart::Gnuplot->new(
    output => "gallery/legend_10.png",
    legend => {
        position => "outside center bottom",
        order    => "horizontal reverse",
        align    => 'left',
        border   => 'on',
    },
);

# Lines
my $lines = Chart::Gnuplot::DataSet->new(
    func  => "cos(x)",

examples/legend_2.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Demonstration of formatting legend
# - position of the legend

my $chart = Chart::Gnuplot->new(
    output => "gallery/legend_2.png",
    legend => {
        position => 'left',
    },
);

# Lines
my $lines = Chart::Gnuplot::DataSet->new(
    func  => "cos(x)",
    title => "cosine",
);

examples/legend_3.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Demonstration of formatting legend
# - add legend border

my $chart = Chart::Gnuplot->new(
    output => "gallery/legend_3.png",
    legend => {
        border => 'on',
    },
);

# Lines
my $lines = Chart::Gnuplot::DataSet->new(
    func  => "cos(x)",
    title => "cosine",
);

examples/legend_4.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Demonstration of formatting legend
# - formatting the legend border

my $chart = Chart::Gnuplot->new(
    output => "gallery/legend_4.png",
    legend => {
        border => {
            linetype => 2,
            width    => 2,
            color    => "navy",
        },
    },
);

# Lines
my $lines = Chart::Gnuplot::DataSet->new(

examples/legend_5.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Demonstration of formatting legend
# - dimension of the legend

my $chart = Chart::Gnuplot->new(
    output => "gallery/legend_5.png",
    legend => {
        width  => 3,
        height => 4,
        border => 'on',
    },
);

# Lines
my $lines = Chart::Gnuplot::DataSet->new(
    func  => "cos(x)",
    title => "cosine",

examples/legend_6.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Demonstration of formatting legend
# - title of the legend

my $chart = Chart::Gnuplot->new(
    output => "gallery/legend_6.png",
    title  => 'Legend with title',
    legend => {
        title  => 'Legend title',
        border => 'on',
    },
);

# Lines
my $lines = Chart::Gnuplot::DataSet->new(
    func  => "cos(x)",
    title => "cosine",
);

examples/legend_7.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Demonstration of formatting legend
# - order of the sample lines

my $chart = Chart::Gnuplot->new(
    output => "gallery/legend_7.png",
    title  => 'Reverse order of the sample lines',
    legend => {
        order => 'reverse',
    },
);

# Lines
my $lines = Chart::Gnuplot::DataSet->new(
    func  => "cos(x)",
    title => "cosine",
);

examples/legend_8.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Demonstration of formatting legend
# - alignment

my $chart = Chart::Gnuplot->new(
    output => "gallery/legend_8.png",
    title  => "Left alignment of the label",
    legend => {
        align => 'left',
    },
);

# Lines
my $lines = Chart::Gnuplot::DataSet->new(
    func  => "cos(x)",
    title => "cosine",
);

examples/legend_9.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Demonstration of formatting legend
# - format the sample lines

my $chart = Chart::Gnuplot->new(
    output => "gallery/legend_9.png",
    title  => "Format the sample lines",
    legend => {
        sample => {
            length   => 10,
            position => 'left',
            spacing  => 2,
        }
    },
);

# Lines
my $lines = Chart::Gnuplot::DataSet->new(

examples/list.html  view on Meta::CPAN

<a href="main.html#Range of the plot" target=main>Range of the plot</a>
<br/>
<a href="main.html#Formatting the chart title" target=main>Formatting the chart title</a>
<br/>
<a href="main.html#Formatting the axis label" target=main>Formatting the axis label</a>
<br/>
<a href="main.html#Formatting the axis tics" target=main>Formatting the axis tics</a>
<br/>
<a href="main.html#Formatting the grid lines" target=main>Formatting the grid lines</a>
<br/>
<a href="main.html#Formatting the legend" target=main>Formatting the legend</a>
<br/>
<a href="main.html#Formatting the graph borders" target=main>Formatting the graph borders</a>
<br/>
<a href="main.html#Date and time data" target=main>Date and time data</a>
<br/>
<a href="main.html#Plot on the secondary axes" target=main>Plot on the secondary axes</a>
<br/>
<a href="main.html#Chart dimension" target=main>Chart dimension</a>
<br/>
<a href="main.html#Background color" target=main>Background color</a>

examples/main.html  view on Meta::CPAN

<td width=65%>Add a chart title</td>
<td align="center"><a href="chartFmt_1.pl">script</a></td>
<td align="center"><a href="gallery/chartFmt_1.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Add axis labels</td>
<td align="center"><a href="chartFmt_2.pl">script</a></td>
<td align="center"><a href="gallery/chartFmt_2.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Add legend</td>
<td align="center"><a href="chartFmt_3.pl">script</a></td>
<td align="center"><a href="gallery/chartFmt_3.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Add grid lines</td>
<td align="center"><a href="chartFmt_4.pl">script</a></td>
<td align="center"><a href="gallery/chartFmt_4.png">sample image</a></td>
</tr>
</table>

examples/main.html  view on Meta::CPAN

<td align="center"><a href="gallery/grid_8.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Composite example</td>
<td align="center"><a href="grid_9.pl">script</a></td>
<td align="center"><a href="gallery/grid_9.png">sample image</a></td>
</tr>
</table>


<!-- ----- Formatting the legend ----- -->
<a name="Formatting the legend">
<h2 style="color:green">Formatting the legend</h2>
</a>
<table border=0 width=100%>
<tr>
<td width=65%>Use default settings</td>
<td align="center"><a href="legend_1.pl">script</a></td>
<td align="center"><a href="gallery/legend_1.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Position</td>
<td align="center"><a href="legend_2.pl">script</a></td>
<td align="center"><a href="gallery/legend_2.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Add border</td>
<td align="center"><a href="legend_3.pl">script</a></td>
<td align="center"><a href="gallery/legend_3.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Format the border</td>
<td align="center"><a href="legend_4.pl">script</a></td>
<td align="center"><a href="gallery/legend_4.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Dimension</td>
<td align="center"><a href="legend_5.pl">script</a></td>
<td align="center"><a href="gallery/legend_5.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Legend title</td>
<td align="center"><a href="legend_6.pl">script</a></td>
<td align="center"><a href="gallery/legend_6.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Order of the sample lines</td>
<td align="center"><a href="legend_7.pl">script</a></td>
<td align="center"><a href="gallery/legend_7.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Alignment of the label</td>
<td align="center"><a href="legend_8.pl">script</a></td>
<td align="center"><a href="gallery/legend_8.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Format the sample lines</td>
<td align="center"><a href="legend_9.pl">script</a></td>
<td align="center"><a href="gallery/legend_9.png">sample image</a></td>
</tr>
<tr>
<td width=65%>Composite example</td>
<td align="center"><a href="legend_10.pl">script</a></td>
<td align="center"><a href="gallery/legend_10.png">sample image</a></td>
</tr>
</table>


<!-- ----- Formatting the graph borders ----- -->
<a name="Formatting the graph borders">
<h2 style="color:green">Formatting the graph borders</h2>
</a>
<table border=0 width=100%>
<tr>

lib/Chart/Gnuplot.pm  view on Meta::CPAN

                        push(@sets, "m$axis"."tics");
                    }
                }
                push(@sets, $attr);
            }
            else
            {
                print PLT "unset $attr\n";
            }
        }
        elsif ($attr eq 'legend')
        {
            print PLT "set key".&_setLegend($self->{legend})."\n";
            push(@sets, 'key');
        }
        elsif ($attr eq 'border')
        {
            if (defined $self->{border})
            {
                print PLT "set border";
                print PLT " ".&_borderCode($self->{border}->{sides}) if
                    (defined $self->{border}->{sides});
                print PLT &_setBorder($self->{border})."\n";

lib/Chart/Gnuplot.pm  view on Meta::CPAN

{
    my ($grid) = @_;
    return($grid) if (ref($grid) eq 'HASH');

    my %out;
    $out{xlines} = $out{ylines} = $out{zlines} = $grid;
    return(\%out);
}


# Set the details of the graph border and legend box border
# - called by _setChart()
#
# Usage example:
# border => {
#      linetype => 3,            # default: solid
#      width    => 2,            # default: 0
#      color    => '#ff00ff',    # default: system defined
#      layer    => 'back',       # default: front
# },
#

lib/Chart/Gnuplot.pm  view on Meta::CPAN

    my $out = '';
	$out .= " $$border{layer}" if (defined $$border{layer});
    $out .= " linetype ".&_lineType($$border{linetype}) if
        (defined $$border{linetype});
    $out .= " linecolor rgb \"$$border{color}\"" if (defined $$border{color});
    $out .= " linewidth $$border{width}" if (defined $$border{width});
    return($out);
}


# Format the legend (key)
#
# Usage example:
# legend => {
#    position => "outside bottom",
#    width    => 3,
#    height   => 4,
#    align    => "right",
#    order    => "horizontal reverse",
#    title    => "Title of the legend",
#    sample   => {
#        length   => 3,
#        position => "left",
#        spacing  => 2,
#    },
#    border   => {
#        linetype => 2,
#        width    => 1,
#        color    => "blue",
#    },
# },
sub _setLegend
{
    my ($legend) = @_;

    my $out = '';
    if (defined $$legend{position})
    {
        ($$legend{position} =~ /\d/)? ($out .= " at $$legend{position}"):
            ($out .= " $$legend{position}");
    }
    $out .= " width $$legend{width}" if (defined $$legend{width});
    $out .= " height $$legend{height}" if (defined $$legend{height});
    if (defined $$legend{align})
    {
        $out .= " Left" if ($$legend{align} eq 'left');
        $out .= " Right" if ($$legend{align} eq 'right');
    }
    if (defined $$legend{order})
    {
        my $order = $$legend{order};
        $order =~ s/reverse/invert/;
        $out .= " $order";
    }
    if (defined $$legend{title})
    {
        if (ref($$legend{title}) eq 'HASH')
        {
            my $title = $$legend{title};
            $out .= " title \"$$title{text}\"";
            $out .= " noenhanced" if (!defined $$title{enhanced} ||
                $$title{enhanced} ne 'on');
        }
        else
        {
            $out .= " title \"$$legend{title}\" noenhanced";
        }
    }
    if (defined $$legend{sample})
    {
        $out .= " samplen $$legend{sample}{length}" if
            (defined $$legend{sample}{length});
        $out .= " reverse" if (defined $$legend{sample}{position} ||
            $$legend{sample}{position} eq "left");
        $out .= " spacing $$legend{sample}{spacing}" if
            (defined $$legend{sample}{spacing});
    }
    if (defined $$legend{border})
    {
        if (ref($$legend{border}) eq 'HASH')
        {
            $out .= " box ".&_setBorder($$legend{border});
        }
        elsif ($$legend{border} eq "off")
        {
            $out .= " no box";
        }
        elsif ($$legend{border} eq "on")
        {
            $out .= " box";
        }
    }
    return($out);
}


# Set title and layout of the multiplot
sub _setMultiplot

lib/Chart/Gnuplot.pm  view on Meta::CPAN

    length    : length of the tics
    along     : where the tics are put (axis/border)
    minor     : number of minor tics between adjacant major tics
    mirror    : turn on and off the tic label of the secondary axis. No effect
              : for C<ztics> (on/off)

=head3 x2tics, y2tics

The tics and tic label of the secondary axes. See L<xtics, ytics, ztics>.

=head3 legend

Legend describing the plots. Supported properties are:

    position : position of the legend
    width    : number of character widths to be added or subtracted to the
             : region of the legend
    height   : number of character heights to be added or subtracted to the
             : region of the legend
    align    : alignment of the text label. Left or right (default)
    order    : order of the keys
    title    : title of the legend
    sample   : format of the sample lines
    border   : border of the legend
    
See L<border> for the available options of border

E.g.

    legend => {
       position => "outside bottom",
       width    => 3,
       height   => 4,
       align    => "right",
       order    => "horizontal reverse",
       title    => "Title of the legend",
       sample   => {
           length   => 3,
           position => "left",
           spacing  => 2,
       },
       border   => {
           linetype => 2,
           width    => 1,
           color    => "blue",
       },

lib/Chart/Gnuplot.pm  view on Meta::CPAN

    if ... than else ...     : ?:, e.g., a ? b : c

Parametric functions may be represented as hash. E.g.

    func => {x => 'sin(t)', y => 'cos(t)'}

will draw a circle.

=head3 title

Title of the dataset (shown in the legend).

=head3 style

The plotting style for the dataset, including

    lines          : join adjacent points by straight lines
    points         : mark each points by a symbol
    linespoints    : both "lines" and "points"
    dots           : dot each points. Useful for large datasets
    impluses       : draw a vertical line from the x-axis to each point

lib/Chart/Gnuplot.pm  view on Meta::CPAN

    my $chart = Chart::Gnuplot->new(
        output => "file.png"
    );

    my $dataSet = Chart::Gnuplot::DataSet->new(
        datafile => "in.dat"
    );

    $chart->plot2d($dataSet);

=item 5. Chart title, axis label and legend

    # Chart object
    my $chart = Chart::Gnuplot->new(
        output => "trigonometric.gif",
        title  => "Three basic trigonometric functions",
        xlabel => "angle in radian",
        ylabel => "function value"
    );

    # Data set objects

t/legend.t  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Test::More (tests => 2);

BEGIN {use Chart::Gnuplot;}

my $temp = "temp.ps";

# Test default setting of legend
{
    my $d = Chart::Gnuplot::DataSet->new(
        func  => "cos(x)",
        title => "cosine function",
    );

    ok($d->_thaw() eq "cos(x) title \"cosine function\"");
}


# Test formatting the legend
{
    my $c = Chart::Gnuplot->new(
        output => $temp,
        legend => {
            position => "outside center bottom",
            order    => "horizontal reverse",
            align    => 'left',
            width    => 3,
            height   => 4,
            title    => 'Trigonometric functions',
            sample   => {length => 10, position => 'left', spacing => 2},
            border   => 'on',
        },
    );

    $c->_setChart();
    ok(&diff($c->{_script}, "legend_1.gp") == 0);
}

###################################################################

# Compare two files
# - return 0 if two files are the same, except the ordering of the lines
# - return 1 otherwise
sub diff
{
    my ($f1, $f2) = @_;



( run in 0.893 second using v1.01-cache-2.11-cpan-49f99fa48dc )