PHP code example of abbadon1334 / gnuplot

1. Go to this page and download the library: Download abbadon1334/gnuplot library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abbadon1334 / gnuplot example snippets




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)
    ;



// Write the graph to out.png
$plot->writePng('out.png');



header('Content-type: image/png');
echo $plot->get();



$plot->display();



$plot->refresh();