.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Chart::Gnuplot 3pm" .TH Chart::Gnuplot 3pm "2022-06-10" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Chart::Gnuplot \- Plot graph using Gnuplot in Perl on the fly .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Chart::Gnuplot; \& \& # Data \& my @x = (\-10 .. 10); \& my @y = (0 .. 20); \& \& # Create chart object and specify the properties of the chart \& my $chart = Chart::Gnuplot\->new( \& output => "fig/simple.png", \& title => "Simple testing", \& xlabel => "My x\-axis label", \& ylabel => "My y\-axis label", \& .... \& ); \& \& # Create dataset object and specify the properties of the dataset \& my $dataSet = Chart::Gnuplot::DataSet\->new( \& xdata => \e@x, \& ydata => \e@y, \& title => "Plotting a line from Perl arrays", \& style => "linespoints", \& .... \& ); \& \& # Plot the data set on the chart \& $chart\->plot2d($dataSet); \& \& ################################################## \& \& # Plot many data sets on a single chart \& $chart\->plot2d($dataSet1, $dataSet2, ...); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This Perl module is to plot graphs uning \s-1GNUPLOT\s0 on the fly. In order to use this module, gnuplot need to be installed. If image format other than \s-1PS\s0 and \&\s-1EPS\s0 is required to generate, it is recommended to install the convert program of ImageMagick as well. Please refer to \*(L"\s-1MECHANISM OF THIS MODULE\*(R"\s0 for details. .PP To plot chart using Chart::Gnuplot, a chart object and at least one dataset object are required. Information about the chart such as output file, chart title, axes labels and so on is specified in the chart object. Dataset object contains information about the dataset to be plotted, including source of the data points, dataset label, color used to plot and more. .PP After chart object and dataset object(s) are created, the chart can be plotted using the plot2d, plot3d or multiplot method of the chart object, e.g. .PP .Vb 2 \& # $chart is the chart object \& $chart\->plot2d($dataSet1, $dataSet2, ...); .Ve .PP To illustate the features of Chart::Gnuplot, the best way is to show by examples. A lot of examples can be found in SourceForge . .SH "MECHANISM OF THIS MODULE" .IX Header "MECHANISM OF THIS MODULE" Casual users may skip this session. .PP When the plotting method (e.g. plot2d) is called, Chart::Gnuplot would generate a Gnuplot script based on the information in the chart object and dataset object. Then it would call the Gnuplot program. Unless specified explicitly in terminal of the Chart object, Chart::Gnuplot would by default generate the image in \s-1PS\s0 format first and then convert the image (by ImageMagick) based on the extension of the filename. The rationale of this approach is that the postscript terminal is so far the best developed teriminal and so this would let users to enjoy the power of Gnuplot as much as possible. .PP Because the default terminal is postscript, if ImageMagick is not installed, you would always need to specify the terminal if the output format is not \s-1PS\s0 (or \s-1EPS\s0). .PP On the other hand, for some image formats, e.g. mousing supported \s-1SVG,\s0 which ImageMagick cannot be converted to, the terminal must be set explicitly (e.g., \&\f(CW\*(C`svg mousing\*(C'\fR in this case). .SH "CHART OBJECT" .IX Header "CHART OBJECT" The chart object can be initiated by the c method. Properties of the chart may be specified optionally when the object is initiated: .PP .Vb 1 \& my $chart = Chart::Gnuplot\->new(%options); .Ve .SS "Chart Options" .IX Subsection "Chart Options" \fIoutput\fR .IX Subsection "output" .PP Output file of the graph. E.g. .PP .Vb 1 \& output => "fig/chart.png", .Ve .PP By default, the image format is detected automatically by the extension of the filename. (Please refer to \*(L"\s-1MECHANISM OF THIS MODULE\*(R"\s0 for details). However, it can also be changed manually by the terminal option or the format conversion methods such as convert and png. .PP Some of image formats that can be detected automatically are: .PP .Vb 12 \& bmp : Microsoft Windows bitmap \& epdf : Encapsulated Portable Document Format \& epi : Encapsulated PostScript Interchange format \& eps : Encapsulated PostScript \& gif : Graphics Interchange Format \& jpg : Joint Photographic Experts Group JFIF format \& pdf : Portable Document Format \& png : Portable Network Graphics \& ppm : Portable Pixmap Format \& ps : PostScript file \& psd : Adobe Photoshop bitmap file \& xpm : X Windows system pixmap .Ve .PP If the filename has no extension, postscipt format will be output. .PP \fItitle\fR .IX Subsection "title" .PP Title of the chart. E.g., .PP .Vb 1 \& title => "Chart title" .Ve .PP Properties of the chart title can be specified in hash. E.g., .PP .Vb 5 \& title => { \& text => "Chart title", \& font => "arial, 20", \& .... \& } .Ve .PP Supported properties are: .PP .Vb 5 \& text : title in plain text \& font : font face (and optionally font size) \& color : font color \& offset : offset relative to the default position \& enhanced : title contains subscript/superscipt/greek? (on/off) .Ve .PP Default values would be used for properties not specified. These properties has no effect on the main title of the multi-chart (see multiplot). .PP \fIxlabel, ylabel, zlabel\fR .IX Subsection "xlabel, ylabel, zlabel" .PP Label of the x\-axis, y\-axis and z\-axis. E.g. .PP .Vb 1 \& xlabel => "Bottom axis label" .Ve .PP Properties of the axis label can be specified in hash, similar to the chart title. Supported properties are: .PP .Vb 6 \& text : title in plain text \& font : font face (and optionally font size) \& color : font color \& offset : offset relative to the default position \& rotate : rotation in degrees \& enhanced : title contains subscript/superscipt/greek? (on/off) .Ve .PP \fIx2label, y2label\fR .IX Subsection "x2label, y2label" .PP Label of the secondary x\-axis (displayed on the top of the graph) and the secondary y\-axis (displayed on the right of the graph). See xlabel. .PP \fIxrange, yrange, zrange\fR .IX Subsection "xrange, yrange, zrange" .PP Range of the x\-axis, y\-axis and z\-axis in the plot, e.g. .PP .Vb 1 \& xrange => [0, "pi"] .Ve .PP would make the plot from x = 0 to x = 3.14159... .PP \fIx2range, y2range\fR .IX Subsection "x2range, y2range" .PP Range of the secondary (top horizontal and right vertical) axes of the plot. See \*(L"xrange, yrange, zrange\*(R". .PP \fItrange, urange, vrange\fR .IX Subsection "trange, urange, vrange" .PP Range of the parametric parameter (t for 2D plots, while u and v for 3D plots). See \*(L"xrange, yrange, zrange\*(R". .PP \fIxtics, ytics, ztics\fR .IX Subsection "xtics, ytics, ztics" .PP The tics and tic label on the x\-axis, y\-axis and z\-axis. E.g. .PP .Vb 5 \& xtics => { \& labels => [\-10, 15, 20, 25], \& labelfmt => "%3f", \& .... \& } .Ve .PP If you set this to \f(CW\*(C`undef\*(C'\fR. E.g., .PP .Vb 1 \& xtics => undef .Ve .PP Then this option will be explicitly \fIunset\fR and the chart will have not have tic marks on the specified axis. .PP Supported properties are: .PP .Vb 10 \& labels : the locations of the tic labels \& start : the starting value for manually\-specified range \& incr : the increment for manually\-specified range \& end : the ending value for manually\-specified range \& labelfmt : format of the labels \& font : font of the labels \& fontsize : font size of the lebals \& fontcolor : font color of the label \& offset : position of the tic labels shifted from its default \& rotate : rotation of the tic labels \& 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 (on/off) .Ve .PP \fIx2tics, y2tics\fR .IX Subsection "x2tics, y2tics" .PP The tics and tic label of the secondary axes. See \*(L"xtics, ytics, ztics\*(R". .PP \fIlegend\fR .IX Subsection "legend" .PP Legend describing the plots. Supported properties are: .PP .Vb 10 \& 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 .Ve .PP See border for the available options of border .PP E.g. .PP .Vb 10 \& 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", \& }, \& } .Ve .PP \fItimeaxis\fR .IX Subsection "timeaxis" .PP Specify the axes of which the tic labels are date/time string. Possible values are combinations of \*(L"x\*(R", \*(L"y\*(R", \*(L"x2\*(R", and \*(L"y2\*(R" joined by \*(L",\*(R". E.g. .PP .Vb 1 \& timeaxis => "x, y2" .Ve .PP means that the x\-axis and y2\-axis are data/time axes. .PP \fIborder\fR .IX Subsection "border" .PP Border of the graph. Properties supported are: .PP .Vb 4 \& sides : sides on which border is displayed \& linetype : line type \& width : line width \& color : line coler .Ve .PP E.g. .PP .Vb 6 \& border => { \& sides => "bottom, left", \& linetype => 3, \& width => 2, \& color => \*(Aq#ff00ff\*(Aq, \& } .Ve .PP \&\f(CW\*(C`sides\*(C'\fR tells which side(s) will be displayed. Default is all four borders for 2D plots, and four bottom and left vertial borders for 3D plots. Acceptable valurs are the 12\-bit code (see the Gnuplot manual) or the following names: .PP .Vb 10 \& bottom \& left \& top \& right \& bottom left front \& bottom left back \& bottom right front \& bottom right back \& left vertical \& right vertical \& front vertical \& back vertical \& top left front \& top left back \& top right front \& top right back .Ve .PP If you set this to \f(CW\*(C`undef\*(C'\fR. E.g., .PP .Vb 1 \& border => undef .Ve .PP Then this option will be explicitly \fIunset\fR and the chart will have not have any border. .PP \fIgrid\fR .IX Subsection "grid" .PP Major grid lines. E.g. .PP .Vb 5 \& grid => { \& linetype => \*(Aqdash\*(Aq, \& width => 2, \& .... \& } .Ve .PP Supported properties are: .PP .Vb 5 \& linetype : line type of the grid lines (default: dot) \& width : line width (defaulr: 0) \& color : line color (default: black) \& xlines : whether the vertical grid lines are drawn (on/off) \& ylines : whether the horizontal grid lines are drawn (on/off) .Ve .PP \fItmargin, bmargin\fR .IX Subsection "tmargin, bmargin" .PP Top and bottom margin (in character height). This option has no effect in 3D plots. E.g. .PP .Vb 1 \& tmargin => 10 .Ve .PP \fIlmargin, rmargin\fR .IX Subsection "lmargin, rmargin" .PP Left amd right margin (in character width). This option has no effect in 3D plots. See \*(L"tmargin, bmargin\*(R". .PP \fIorient\fR .IX Subsection "orient" .PP Orientation of the image. Possible values are \*(L"lanscape\*(R" (default) and \&\*(L"portrait\*(R". E.g. .PP .Vb 1 \& orient => "portrait" .Ve .PP \fIimagesize\fR .IX Subsection "imagesize" .PP Size (length and height) of the image relative to the default. E.g. .PP .Vb 1 \& imagesize => "0.8, 0.5" .Ve .PP \fIsize\fR .IX Subsection "size" .PP Size of the plot relative to the chart size. This is useful in some multi-plot such as inset chart. E.g. .PP .Vb 1 \& size => "0.5, 0.4" .Ve .PP \fIorigin\fR .IX Subsection "origin" .PP Origin of the chart. This is useful in some multi-plot such as inset chart. E.g. .PP .Vb 1 \& origin => "0.1, 0.5" .Ve .PP \fItimestamp\fR .IX Subsection "timestamp" .PP Time stamp of the plot. To place the time stamp with default setting, .PP .Vb 1 \& timestamp => \*(Aqon\*(Aq .Ve .PP Properties of the time stamp (such as date-time format) can also be set, e.g. .PP .Vb 5 \& timestamp => { \& fmt => \*(Aq%d/%m/%y %H:%M\*(Aq, \& offset => "10,\-3", \& font => "Helvetica", \& } .Ve .PP Supported properties are: .PP .Vb 3 \& fmt : date\-time format \& offset : offset relative to the default position \& font : font face (and optionally font size) .Ve .PP \fIbg\fR .IX Subsection "bg" .PP Background color of the chart. This option has no effect in the sub-chart of multiplot. E.g. to give the chart a yellow background, .PP .Vb 1 \& bg => "yellow" .Ve .PP Properties can be specified in hash. E.g., .PP .Vb 4 \& bg => { \& color => "yellow", \& density => 0.2, \& } .Ve .PP Supported properties are: .PP .Vb 2 \& color : color (name ot RRGGBB value) \& density : density of the coloring .Ve .PP \fIplotbg\fR .IX Subsection "plotbg" .PP Background color of the plot area. This option has no effect in 3D plots. See bg for supported properties. .PP \fIgnuplot\fR .IX Subsection "gnuplot" .PP The path of Gnuplot executable. This option is useful if you are using Windows or have multiple versions of Gnuplot installed. E.g., .PP .Vb 1 \& gnuplot => "C:\eProgram Files\e...\egnuplot\ebin\ewgnuplot.exe" # for Windows .Ve .PP \fIconvert\fR .IX Subsection "convert" .PP The path of convert executable of ImageMagick. This option is useful if you have multiple convert executables. .PP \fIterminal\fR .IX Subsection "terminal" .PP The terminal driver that Gnuplot uses. E.g., .PP .Vb 1 \& terminal => \*(Aqsvg mousing\*(Aq .Ve .PP The default value is \f(CW\*(C`postscript enhanced color\*(C'\fR. Terminal is not necessarily related to the output image format. E.g., you may use gif terminal and then convert the image format to jpg by the \fBconvert()\fR method. .SS "Chart Options Not Mentioned Above" .IX Subsection "Chart Options Not Mentioned Above" If Chart::Gnuplot encounters options not mentions above, it would convert them to Gnuplot set statements. E.g. if the chart object is .PP .Vb 4 \& $chart = Chart::Gnuplot\->new( \& ... \& foo => "FOO", \& ); .Ve .PP the generated Gnuplot statements would be: .PP .Vb 2 \& ... \& set foo FOO .Ve .PP This mechanism lets Chart::Gnuplot support many features not mentioned above (such as \*(L"cbrange\*(R", \*(L"samples\*(R", \*(L"view\*(R" and so on). .SS "Chart Methods" .IX Subsection "Chart Methods" \fInew\fR .IX Subsection "new" .PP .Vb 1 \& my $chart = Chart::Gnuplot\->new(%options); .Ve .PP Constructor of the chart object. If no option is specified, default values would be used. See \*(L"Chart Options\*(R" for available options. .PP \fIset\fR .IX Subsection "set" .PP General set methods for arbitrary number of options. .PP .Vb 1 \& $chart\->set(%options); .Ve .PP E.g. .PP .Vb 1 \& $chart\->set(view => \*(Aq30,60\*(Aq); .Ve .PP will be translated to the Gnuplot statement .PP .Vb 1 \& set view 30,60 .Ve .PP \fIplot2d\fR .IX Subsection "plot2d" .PP .Vb 1 \& $chart\->plot2d(@dataSets); .Ve .PP Plot the data sets in a 2D chart. Each dataset is represented by a dataset object. .PP \fIplot3d\fR .IX Subsection "plot3d" .PP .Vb 1 \& $chert\->plot3d(@dataSets); .Ve .PP Plot the data sets in a 3D chart. Each dataset is represented by a dataset object. .PP \fImultiplot\fR .IX Subsection "multiplot" .PP .Vb 1 \& $chart\->multiplot(@charts); .Ve .PP Plot multiple charts in the same image. .PP \fIanimate\fR .IX Subsection "animate" .PP Create animated gif. E.g. .PP .Vb 4 \& # Create (main) chart object \& my $chart = Chart::Gnuplot\->new( \& output => "animate.gif", \& ); \& \& # Add frames to the (main) chart object \& my $T = 30; # number of frames \& my @c; \& for (my $i = 0; $i < $T; $i++) \& { \& $c[$i] = Chart::Gnuplot\->new(xlabel => \*(Aqx\*(Aq); \& my $ds = Chart::Gnuplot::DataSet\->new( \& func => "sin($i*2*pi/$T + x)", \& ); \& $c[$i]\->add2d($ds); \& } \& \& # Create animation \& $chart\->animate( \& charts => \e@c, \& delay => 10, # delay 0.1 sec between successive images \& ); .Ve .PP Supported properties are: .PP .Vb 3 \& charts : chart sequence used to create the animation \& delay : delay (in units of 0.01 second) between successive images, default \& : value is 5 .Ve .PP See add2d and add3d. .PP \fIadd2d\fR .IX Subsection "add2d" .PP Add a 2D dataset to a chart without plotting it out immediately. Used with \&\f(CW\*(C`multiplot\*(C'\fR or \f(CW\*(C`animate\*(C'\fR. .PP \fIadd3d\fR .IX Subsection "add3d" .PP Add a 3D dataset to a chart without plotting it out immediately. Used with \&\f(CW\*(C`multiplot\*(C'\fR or \f(CW\*(C`animate\*(C'\fR. .PP \fIlabel\fR .IX Subsection "label" .PP Add an arbitrary text label. e.g., .PP .Vb 11 \& $chart\->label( \& text => "This is a label", \& position => "0.2, 3 left", \& offset => "2,2", \& rotate => 45, \& font => "arial, 15", \& fontcolor => "dark\-blue", \& pointtype => 3, \& pointsize => 5, \& pointcolor => "blue", \& ); .Ve .PP Supported properties are: .PP .Vb 9 \& text : label text \& position : position of the label \& offset : offset relative to the default position \& rotate : rotation in degrees \& font : font face (and optionally font size) \& fontcolor : color of the text \& pointtype : point type \& pointsize : point size \& pointcolor : point color .Ve .PP \fIarrow\fR .IX Subsection "arrow" .PP Draw arbitrary arrow. e.g., .PP .Vb 11 \& $chart\->arrow( \& from => "0,2", \& to => "0.3,0.1", \& linetype => \*(Aqdash\*(Aq, \& width => 2, \& color => "dark\-blue", \& head => { \& size => 2, \& angle => 30, \& }, \& ); .Ve .PP Supported properties are: .PP .Vb 7 \& from : starting position \& to : ending position (position of the arrow head) \& rto : ending position relative to the starting position \& linetype : line type \& width : line width \& color : color \& head : arrow head .Ve .PP Supported properties of the arrow head are: .PP .Vb 3 \& size : size of the head \& angle : angle (in degree) between the arrow and the head branch \& direction : head direction (\*(Aqback\*(Aq, \*(Aqboth\*(Aq or \*(Aqoff\*(Aq) .Ve .PP \fIline\fR .IX Subsection "line" .PP Draw arbitrary straight line. e.g., .PP .Vb 7 \& $chart\->line( \& from => "0,2", \& to => "0.3,0.1", \& linetype => \*(Aqdash\*(Aq, \& width => 2, \& color => "dark\-blue", \& ); .Ve .PP Supported properties are: .PP .Vb 6 \& from : starting position \& to : ending position (position of the arrow head) \& rto : ending position relative to the starting position \& linetype : line type \& width : line width \& color : color .Ve .PP \fIrectangle\fR .IX Subsection "rectangle" .PP Draw arbitrary rectangle. e.g., .PP .Vb 12 \& $chart\->rectangle( \& from => "screen 0.2, screen 0.2", \& to => "screen 0.4, screen 0.4", \& fill => { \& density => 0.2, \& color => "#11ff11", \& }, \& border => {color => "blue"}, \& linewidth => 3, \& layer => \*(Aqfront\*(Aq, \& index => 1, \& ); .Ve .PP Most properties of a rectangle can be classified into location, dimension, filling and border. Location and dimension of the rectangle can be specified by \&\f(CW\*(C`from\*(C'\fR and \f(CW\*(C`to\*(C'\fR, or \f(CW\*(C`from\*(C'\fR and \f(CW\*(C`rto\*(C'\fR, or \f(CW\*(C`at\*(C'\fR, \f(CW\*(C`width\*(C'\fR and \f(CW\*(C`height\*(C'\fR. Filling can be specified by \f(CW\*(C`color\*(C'\fR and \f(CW\*(C`density\*(C'\fR, or \f(CW\*(C`pattern\*(C'\fR. Border has only one property \f(CW\*(C`color\*(C'\fR so far. Besides, \f(CW\*(C`linewidth\*(C'\fR controls the line width of the border as well as the filling pattern. The layer that the rectangle is drawn is set by \f(CW\*(C`layer\*(C'\fR. The \f(CW\*(C`index\*(C'\fR is a tag of the rectangle, which usually can be omitted. .PP \fIellipse\fR .IX Subsection "ellipse" .PP Draw arbitrary ellipse. e.g., .PP .Vb 7 \& $chart\->ellipse( \& at => "screen 0.2, screen 0.2", \& width => 0.2, \& height => 0.5 \& fill => {pattern => 2}, \& border => {color => "blue"}, \& ); .Ve .PP The properties of \f(CW\*(C`ellipse\*(C'\fR is the same as those of rectangle, except that its location and dimension must be set by \f(CW\*(C`at\*(C'\fR, \f(CW\*(C`width\*(C'\fR and \f(CW\*(C`height\*(C'\fR. .PP \fIcircle\fR .IX Subsection "circle" .PP Draw arbitrary circle. e.g., .PP .Vb 6 \& $chart\->circle( \& at => "screen 0.2, screen 0.2", \& size => 0.5 \& fill => {pattern => 2}, \& layer => \*(Aqbehind\*(Aq, \& ); .Ve .PP The properties of \f(CW\*(C`circle\*(C'\fR is the same as those of rectangle, except that its location and dimension must be set by \f(CW\*(C`at\*(C'\fR, \f(CW\*(C`width\*(C'\fR and \f(CW\*(C`height\*(C'\fR. .PP \fIpolygon\fR .IX Subsection "polygon" .PP Draw arbitrary polygon. e.g., .PP .Vb 10 \& $chart\->polygon( \& vertices => [ \& " 0, 0.2", \& "\-2, \-0.2", \& {to => "2, \-0.3"}, \& {rto => "0, 0.3"}, \& ], \& fill => {pattern => 2}, \& border => {color => "blue"}, \& ); .Ve .PP The location and dimension of the polygon are specified by an array of \&\f(CW\*(C`vertices\*(C'\fR. Except \f(CW\*(C`border\*(C'\fR, \f(CW\*(C`pattern\*(C'\fR of \f(CW\*(C`fill\*(C'\fR, \f(CW\*(C`index\*(C'\fR and \f(CW\*(C`layer\*(C'\fR, other properties of rectangle is not supported. .PP \fIcopy\fR .IX Subsection "copy" .PP Copy the chart object. This method is especially useful when you want to copy a chart with highly customized format. E.g. .PP .Vb 3 \& my $chart = Chart::Gnuplot\->new( \& ... \& ); \& \& # $copy is a copy of $chart \& my $copy = $chart\->copy; .Ve .PP You may also make multiple copies . E.g. .PP .Vb 1 \& my @copies = $chart\->copy(10); # make 10 copies .Ve .PP \fIconvert\fR .IX Subsection "convert" .PP Convert the image format by ImageMagick, e.g. .PP .Vb 1 \& $chart\->convert(\*(Aqpng\*(Aq); .Ve .PP \fIpng\fR .IX Subsection "png" .PP .Vb 1 \& $chart\->png; .Ve .PP Change the image format to \s-1PNG.\s0 .PP \fIgif\fR .IX Subsection "gif" .PP .Vb 1 \& $chart\->gif; .Ve .PP Change the image format to \s-1GIF.\s0 .PP \fIjpg\fR .IX Subsection "jpg" .PP .Vb 1 \& $chart\->jpg; .Ve .PP Change the image format to \s-1JPEG.\s0 .PP \fIps\fR .IX Subsection "ps" .PP .Vb 1 \& $chart\->ps; .Ve .PP Change the image format to postscript. .PP \fIpdf\fR .IX Subsection "pdf" .PP .Vb 1 \& $chart\->pdf .Ve .PP Change the image format to \s-1PDF.\s0 .PP \fIcommand\fR .IX Subsection "command" .PP .Vb 1 \& $chart\->command($gnuplotCommand); .Ve .PP Add a gnuplot command. This method is useful for the Gnuplot features that have not yet implemented. .PP .Vb 1 \& $chart\->command(\e@gnuplotCommands); .Ve .PP Add a list of gnuplot commands. .PP \fIexecute\fR .IX Subsection "execute" .PP Execute Gnuplot. Normally users do not need to call this method directly because this method would be called automatically by other methods such as plot2d, multiplot and animate. .SH "DATASET OBJECT" .IX Header "DATASET OBJECT" The dataset object can be initiated by the \f(CW\*(C`new\*(C'\fR method. Properties of the dataset may be specified optionally when the object is initiated: .PP .Vb 1 \& my $dataset = Chart::Gnuplot::DataSet\->new(%options); .Ve .PP The data source of the dataset can be specified by either one of the following ways: .IP "1. Arrays of x values, y values and z values (in 3D plots) of the data points." 4 .IX Item "1. Arrays of x values, y values and z values (in 3D plots) of the data points." .PD 0 .IP "2. Array of data points. Each point is specified as an array of x, y, z coordinates" 4 .IX Item "2. Array of data points. Each point is specified as an array of x, y, z coordinates" .IP "3. Data file." 4 .IX Item "3. Data file." .IP "4. Mathematical expression (for a function)." 4 .IX Item "4. Mathematical expression (for a function)." .PD .SS "Dataset Options" .IX Subsection "Dataset Options" \fIxdata, ydata, zdata\fR .IX Subsection "xdata, ydata, zdata" .PP The x, y, z values of the data points. E.g. .PP .Vb 1 \& xdata => \e@x .Ve .PP If \f(CW\*(C`xdata\*(C'\fR is omitted but \f(CW\*(C`ydata\*(C'\fR is defined, the integer index starting from 0 would be used for \f(CW\*(C`xdata\*(C'\fR. .PP \fIpoints\fR .IX Subsection "points" .PP Data point matrix of the format [[x1,y1], [x2,y2], [x3,y3], ...] .PP .Vb 1 \& points => \e@points .Ve .PP \fIdatafile\fR .IX Subsection "datafile" .PP Input data file .PP .Vb 1 \& datafile => $file .Ve .PP The data files are assumed to be space-separated, with each row corresponding to one data point. Lines beginning with \*(L"#\*(R" are considered as comments and would be ignored. Other formats are not supported at this moment. .PP \fIfunc\fR .IX Subsection "func" .PP Mathematical function to be plotted. E.g. .PP .Vb 1 \& func => "sin(x)*x**3" .Ve .PP Supported functions: .PP .Vb 10 \& abs(x) : absolute value \& acos(x) : inverse cosine \& acosh(x) : inverse hyperbolic cosine \& arg(x) : complex argument \& asin(x) : inverse sine \& asinh(x) : inverse hyperbolic sine \& atan(x) : inverse tangent \& atanh(x) : inverse hyperbolic tangent \& besj0(x) : zeroth order Bessel function of the first kind \& besj1(x) : first order Bessel function of the first kind \& besy0(x) : zeroth order Bessel function of the second kind \& besy1(x) : first order Bessel function of the second kind \& ceil(x) : ceiling function \& cos(x) : cosine \& cosh(x) : hyperbolic cosine \& erf(x) : error function \& erfc(x) : complementary error function \& exp(x) : expontial function \& floor(x) : floor function \& gamma(x) : gamma function \& ibeta(a,b,x) : incomplete beta function \& inverf(x) : inverse error function \& igamma(a,x) : incomplete gamma function \& imag(x) : imaginary part \& invnorm(x) : inverse normal distribution function \& int(x) : integer part \& lambertw(x) : Lambert W function \& lgamma(x) : log gamma function \& log(x) : natural logarithm \& log10(x) : common logarithm \& norm(x) : normal distribution function \& rand(x) : pseudo random number \& real(x) : real part \& sgn(x) : sign function \& sin(x) : sine \& sinh(x) : hyperbolic sine \& sqrt(x) : square root \& tan(x) : tangent \& tanh(x) : hyperbolic tangent .Ve .PP Please see the Gnuplot manual for updated information. .PP Supported mathematical constants: .PP .Vb 1 \& pi : the circular constant 3.14159... .Ve .PP Supported arithmetic operators: .PP .Vb 8 \& addition : + \& division : / \& exponentiation : ** \& factorial : ! \& modulo : % \& multiplication : * \& subtraction : \-, e.g., 1\-2 \& unary minus : \-, e.g., \-1 .Ve .PP Supported logical operations: .PP .Vb 11 \& and : && \& complement : ~ \& equality : == \& greater than : > \& greater than or equal to : >= \& inequality : != \& less than : < \& less than or equal to : <= \& negation : ! \& or : || \& if ... than else ... : ?:, e.g., a ? b : c .Ve .PP Parametric functions may be represented as hash. E.g. .PP .Vb 1 \& func => {x => \*(Aqsin(t)\*(Aq, y => \*(Aqcos(t)\*(Aq} .Ve .PP will draw a circle. .PP \fItitle\fR .IX Subsection "title" .PP Title of the dataset (shown in the legend). .PP \fIstyle\fR .IX Subsection "style" .PP The plotting style for the dataset, including .PP .Vb 10 \& 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 \& steps : join adjacent points by steps \& boxes : draw a centered box from the x\-axis to each point \& xerrorbars : "dots" with horizontal error bars \& yerrorbars : "dots" with vertical error bars \& xyerrorbars : both "xerrorbars" and "yerrorbars" \& xerrorlines : "linespoints" with horizontal error bars \& yerrorlines : "linespoints" with vertical error bars \& xyerrorlines : both "xerrorlines" and "yerrorlines" \& boxerrorbars : "boxes" with "yerrorbars" \& boxxyerrorbars : use rectangles to represent the data with errors \& financebars : finance bars for open, high, low and close price \& candlesticks : candle sticks for open, high, low and close price \& hbars : horizontal bars (experimental) \& hlines : horizontal lines (experimental) \& vectors : arrows \& circles : circles, for say, bubble charts \& histograms : for plotting histograms .Ve .PP \&\f(CW\*(C`hbars\*(C'\fR and \f(CW\*(C`hlines\*(C'\fR are available only if the data is input from \f(CW\*(C`points\*(C'\fR or \f(CW\*(C`(x,y)data\*(C'\fR. .PP \fIcolor\fR .IX Subsection "color" .PP Color of the dataset in the plot. Can be a named color or \s-1RBG\s0 (#RRGGBB) value. The supported color names can be found in the file \fIdoc/colors.txt\fR in the distribution. E.g. .PP .Vb 1 \& color => "#99ccff" .Ve .PP is equivalent to .PP .Vb 1 \& color => "dark\-red" .Ve .PP \fIwidth\fR .IX Subsection "width" .PP Line width used in the plot. The default width is 1. .PP \fIlinetype\fR .IX Subsection "linetype" .PP Line type. Can be an integer or line type name. The supported line type names can be found in the file \fIdoc/linetypes.txt\fR in the distribution. E.g. .PP .Vb 1 \& linetype => 3 .Ve .PP is equivalent to .PP .Vb 1 \& linetype => \*(Aqdash\*(Aq .Ve .PP Note: the line type may not be displayed as the name if \f(CW\*(C`terminal\*(C'\fR is set and is not postscript. .PP \fIpointtype\fR .IX Subsection "pointtype" .PP Point type. Can be an integer or point type name. The supported point type names can be found in the file \fIdoc/pointtypes.txt\fR in the distribution. E.g. .PP .Vb 1 \& pointtype => 64 .Ve .PP is equivalent to .PP .Vb 1 \& pointtype => \*(Aqsquare\*(Aq .Ve .PP Note: the point type may not be displayed as the name if \f(CW\*(C`terminal\*(C'\fR is set and is not postscript. .PP \fIpointsize\fR .IX Subsection "pointsize" .PP Point size of the plot. E.g. .PP .Vb 1 \& pointsize => 3 .Ve .PP The default point size is 1. .PP \fIfill\fR .IX Subsection "fill" .PP Filling the boxes. Has effect only on plotting styles with boxes, such as \&\*(L"boxes\*(R", \*(L"boxxyerrorbars\*(R" and \*(L"financebars\*(R". To fill with pattern, .PP .Vb 3 \& fill => { \& pattern => 1, \& } .Ve .PP \&\f(CW\*(C`pattern\*(C'\fR may be an interger from 0 (no filling) to 7. .PP To fill with solid, .PP .Vb 4 \& fill => { \& color => \*(Aq#33bb33\*(Aq, \& density => 0.2, \& } .Ve .PP \&\f(CW\*(C`color\*(C'\fR may be named color or \s-1RGB\s0 (#RRGGBB). \f(CW\*(C`density\*(C'\fR may be a real number from 0 (empty) to 1. .PP \fIborder\fR .IX Subsection "border" .PP Border of the boxes. Has effect only on plotting styles with boxes and if \&\f(CW\*(C`fill\*(C'\fR is set. \f(CW\*(C`color\*(C'\fR (either named color or \s-1RGB\s0) is the only supported property. E.g. .PP .Vb 3 \& border => { \& color => \*(Aqblue\*(Aq, \& } .Ve .PP \fIaxes\fR .IX Subsection "axes" .PP Axes used in the plot. Possible values are \*(L"x1y1\*(R", \*(L"x1y2\*(R", \*(L"x2y1\*(R" and \*(L"x2y2\*(R". .PP \fItimefmt\fR .IX Subsection "timefmt" .PP Time format of the input data. The valid format are: .PP .Vb 11 \& %d : day of the month, 1\-31 \& %m : month of the year, 1\-12 \& %y : year, 2\-digit, 0\-99 \& %Y : year, 4\-digit \& %j : day of the year, 1\-365 \& %H : hour, 0\-24 \& %M : minute, 0\-60 \& %s : seconds since the Unix epoch (1970\-01\-01 00:00 UTC) \& %S : second, 0\-60 \& %b : name of the month, 3\-character abbreviation \& %B : name of the month .Ve .PP \fIsmooth\fR .IX Subsection "smooth" .PP The smooth method used in plotting data points. Supported methods include cubic splines (csplines), Bezier curve (bezier) and other. Please see Gnuplot manual for details. .PP \fIusing\fR .IX Subsection "using" .PP The \f(CW\*(C`using\*(C'\fR keyword of Gnuplot. .PP \fIevery\fR .IX Subsection "every" .PP The \f(CW\*(C`every\*(C'\fR keyword of Gnuplot. Has effect only if the data is input from \&\f(CW\*(C`datafile\*(C'\fR. .PP \fIindex\fR .IX Subsection "index" .PP The \f(CW\*(C`index\*(C'\fR keyword of Gnuplot. Has effect only if the data is input from \&\f(CW\*(C`datafile\*(C'\fR. .SS "Dataset Methods" .IX Subsection "Dataset Methods" \fInew\fR .IX Subsection "new" .PP .Vb 1 \& my $dataset = Chart::Gnuplot::DataSet\->new(%options); .Ve .PP Constructor of the dataset object. If no option is specified, default values would be used. See \*(L"Dataset Options\*(R" for available options. .PP \fIcopy\fR .IX Subsection "copy" .PP Copy the dataset object. This method is especially useful when you want to copy a dataset with highly customized format. E.g. .PP .Vb 3 \& my $dataset = Chart::Gnuplot::DataSet\->new( \& ... \& ); \& \& # $copy and $dataset will have the same format and contain the same data \& my $copy = $dataset\->copy; .Ve .PP You may also make multiple copies . E.g. .PP .Vb 1 \& my @copies = $dataset\->copy(10); # make 10 copies .Ve .SH "EXAMPLES" .IX Header "EXAMPLES" Some simple examples are shown below. Many more come with the distribution. .IP "1. Plot a mathematical expression" 4 .IX Item "1. Plot a mathematical expression" .Vb 3 \& my $chart = Chart::Gnuplot\->new( \& output => "expression.png" \& ); \& \& my $dataSet = Chart::Gnuplot::DataSet\->new( \& func => "sin(x)" \& ); \& \& $chart\->plot2d($dataSet); .Ve .IP "2. Plot from two Perl arrays, one for the x\-axis data and the other the y\-axis." 4 .IX Item "2. Plot from two Perl arrays, one for the x-axis data and the other the y-axis." .Vb 3 \& my $chart = Chart::Gnuplot\->new( \& output => "arrays.png" \& ); \& \& my $dataSet = Chart::Gnuplot::DataSet\->new( \& xdata => \e@x, \& ydata => \e@y, \& ); \& \& $chart\->plot2d($dataSet); .Ve .IP "3. Plot x\-y pairs" 4 .IX Item "3. Plot x-y pairs" .Vb 7 \& # Data \& my @xy = ( \& [1.1, \-3], \& [1.2, \-2], \& [3.5, 0], \& ... \& ); \& \& my $chart = Chart::Gnuplot\->new( \& output => "points.png" \& ); \& \& my $dataSet = Chart::Gnuplot::DataSet\->new( \& points => \e@xy \& ); \& \& $chart\->plot2d($dataSet); .Ve .IP "4. Plot data from a data file" 4 .IX Item "4. Plot data from a data file" .Vb 3 \& my $chart = Chart::Gnuplot\->new( \& output => "file.png" \& ); \& \& my $dataSet = Chart::Gnuplot::DataSet\->new( \& datafile => "in.dat" \& ); \& \& $chart\->plot2d($dataSet); .Ve .IP "5. Chart title, axis label and legend" 4 .IX Item "5. Chart title, axis label and legend" .Vb 7 \& # 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 \& my $sine = Chart::Gnuplot::DataSet\->new( \& func => "sin(x)", \& title => "sine function" \& ); \& my $cosine = Chart::Gnuplot::DataSet\->new( \& func => "cos(x)", \& title => "cosine function" \& ); \& my $tangent = Chart::Gnuplot::DataSet\->new( \& func => "tan(x)", \& title => "tangent function" \& ); \& \& $chart\->plot2d($sine, $cosine, $tangent); .Ve .IP "6. Title in non-English characters (Thanks to WOLfgang Schricker)" 4 .IX Item "6. Title in non-English characters (Thanks to WOLfgang Schricker)" .Vb 1 \& use Encode; \& \& my $title = ... # Title with German umlauts \& $title = decode("utf8", $title); \& \& Chart::Gnuplot\->new( \& encoding => \*(Aqiso\-8859\-1\*(Aq, \& title => $title, \& ); .Ve .IP "7. Plot a financial time series" 4 .IX Item "7. Plot a financial time series" .Vb 8 \& my $chart = Chart::Gnuplot\->new( \& output => "dj.ps", \& title => "Dow\-Jones Index time series", \& timeaxis => \*(Aqx\*(Aq, \& xtics => { \& labelfmt => \*(Aq%b%y\*(Aq, \& }, \& ); \& \& my $dow = Chart::Gnuplot::DataSet\->new( \& file => "dj.dat", \& timefmt => \*(Aq%Y\-%m\-%d\*(Aq, # time format of the input data \& style => "candlesticks", \& grid => \*(Aqon\*(Aq, \& ); \& \& $chart\->plot2d($dow); .Ve .IP "8. Plot several graphs on the same image" 4 .IX Item "8. Plot several graphs on the same image" .Vb 3 \& my $chart = Chart::Gnuplot\->new( \& output => "multiplot.gif", \& ); \& \& my $left = Chart::Gnuplot\->new(); \& my $sine = Chart::Gnuplot::DataSet\->new( \& func => "sin(x)", \& ); \& $left\->add2d($sine); \& \& my $center = Chart::Gnuplot\->new(); \& my $cosine = Chart::Gnuplot::DataSet\->new( \& func => "cos(x)", \& ); \& $center\->add2d($cosine); \& \& my $right = Chart::Gnuplot\->new(); \& my $tangent = Chart::Gnuplot::DataSet\->new( \& func => "tan(x)", \& ); \& $right\->add2d($tangent); \& \& # Place the Chart::Gnuplot objects in matrix to indicate their locations \& $chart\->multiplot([ \& [$left, $center, $right] \& ]); .Ve .SH "WISH LIST" .IX Header "WISH LIST" .IP "1. Improve the manual." 4 .IX Item "1. Improve the manual." .PD 0 .IP "2. Add curve fitting method." 4 .IX Item "2. Add curve fitting method." .IP "3. Improve the testsuite." 4 .IX Item "3. Improve the testsuite." .IP "4. Reduce number of temporary files generated." 4 .IX Item "4. Reduce number of temporary files generated." .PD .SH "REQUIREMENTS" .IX Header "REQUIREMENTS" Carp, File::Copy, File::Temp, Storable .PP Gnuplot .PP ImageMagick (for full feature) .SH "SEE ALSO" .IX Header "SEE ALSO" Gnuplot official website .SH "AUTHOR" .IX Header "AUTHOR" Ka-Wai Mak .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2008\-2011, 2013\-2015 Ka-Wai Mak. All rights reserved. .SH "LICENSE" .IX Header "LICENSE" This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.