abbadon1334 / gnuplot
GnuPlot library - forked from gregwar/gnuplot
Installs: 46
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 12
pkg:composer/abbadon1334/gnuplot
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2025-10-04 06:02:03 UTC
README
A PHP Library for using GnuPlot
This is the output of the demo/write.php:
Requirements
You need to have a server with gnuplot installed and the safe mode
disabled (to be able to run proc_open())
Usage
There is examples in the demo/ directory.
You can create a graph and populate it like this:
<?php use Gregwar\GnuPlot\GnuPlot; $plot = new GnuPlot; // Setting the main graph title $plot->setGraphTitle('Demo graph'); // Adding three points to the first curve $plot ->setTitle(0, 'The first curve') ->push(0, 4) ->push(1, 5) ->push(2, 6) ; // Adding three points on the other curve and drawing it as a line of connected points, colored in red and smoothed // (with index 1) $plot ->setTitle(1, 'The first curve') ->setLineType(1, 'rgb #ff0000') ->setLineMode(1, 'lp') ->setLineSmooth(1, GnuPlot::SMOOTH_CSPLINE) ->push(0, 8, 1) ->push(1, 9, 1) ->push(2, 10, 1) ; // Drawing the area between the two curves in blue $plot ->setLineMode(2, GnuPlot::LINEMODE_FILLEDCURVES) ->setLineType(2, 'rgb #0000ff') ->setTitle(2, 'Area') ->push(0, [4, 8], 2) ->push(1, [5, 9], 2) ->push(2, [6,10], 2) ;
You can then save it to a file, have a look to write.php for example:
<?php // Write the graph to out.png $plot->writePng('out.png');
Or render it directly into a browser, you can try out.php for
example:
<?php header('Content-type: image/png'); echo $plot->get();
Or display it on the screen (useful with CLI scripts), run the
demo.php script for example:
<?php $plot->display();
Or display it, and re-feed it in real time (with CLI scripts), you can
run realTime.php for example:
<?php $plot->refresh();
API
push($x, $y, $index=0), add a point to the $index-nth curve ($y can be an array if the linemode isGnuPlot::LINEMODE_FILLEDCURVES)display(), renders the graph on the screen (asuming you are using it as a CLI with an X Serverrefresh(), same asdisplay(), but will replot the graph after the first callget(), gets the PNG data for your imagewritePng($filename), writes the data to the output PNG filewritePDF($filename), writes the data to the output PDF filewriteEPS($filename), writes the data to the output EPS filesetTitle($index, $title), sets the title of the $index-nt curvesetLineWidth($index, $width), sets the width of the $index-nt curvesetLineMode($index, $mode), sets the line mode of the $index-nt curve (set toGnuPlot::LINEMODE_FILLEDCURVESto fill an area between two lines)setLinePoint($index, $point), sets the line point of the $index-nt curvesetLineType($index, $type), sets the line type of the $index-nt curvesetLineColor($index, $color), sets the line color of the $index-nt curvesetLineSmooth($index, $smooth), sets the smooth type of the $index-nt curve. Available smooths areSMOOTH_NONE,SMOOTH_BEZIER,SMOOTH_CSPLINE, defined as constants on theGnuPlotclass.setGraphTitle($title), sets the main title for the graphsetXTimeFormat($format), sets the X axis as a time axis and specify data formatsetTimeFormatString($format), specify the X axis time presentation formatsetXLabel($text), sets the label for the X axissetYLabel($text), sets the label for the Y axissetYFormat($format), sets Y axis formattingsetXRange($min, $max), set the X min & maxsetYRange($min, $max), set the Y min & maxsetXTics($tics), set the X ticssetYTics($tics), set the Y ticssetMXTics($tics), set the micro X ticssetMYTics($tics), set the micro Y ticssetMinorGrid($status), enabled/disables the grid for microticssetGridPlacement($layer), sets the placement of the grid, can beGnuPlot::GRID_DEFAULT,GnuPlot::GRID_FRONTorGnuPlot::GRID_BACKsetWidth($width), sets the width of the graphsetHeight($height), sets the height of the graphsetCanvasWidth($width), sets the width of the canvas (if not set, the width value is used)setCanvasHeight($height), sets the height of the canvas (if not set, the height value is used)setOrigin($x, $y), sets the origin of the graphsetSleepTime($sleepTime), sets the sleep time after saving a fileaddLabel($x, $y, $text), add some label at a pointflush(), completely flushes the internal state and resets the object to its initial state
License
Gregwar\GnuPlot is under MIT license
