# PHPlot Example - Horizontal Error Plot require_once 'phplot.php'; # The experimental results as a series of temperature measurements: $results = array(98, 102, 100, 103, 101, 105, 110, 108, 109); # The accuracy of our measuring equipment is +/- 5% $error_factor = 0.05; # Convert the experimental results to a PHPlot data array for error plots. function reduce_data($results, $error_factor) { # Use the average of measurements to approximate the error amount: $err = $error_factor * array_sum($results) / count($results); # Build the 'data-data-yx-error' data array: $data = array(); $i = 1; foreach ($results as $value) { $data[] = array("Sample {$i}", $i++, $value, $err, $err); } return $data; } $plot = new PHPlot(800, 600); $plot->SetTitle('Experiment Results'); $plot->SetXTitle('Melting Temperature (degrees C)'); $plot->SetDataValues(reduce_data($results, $error_factor)); $plot->SetDataType('data-data-yx-error'); $plot->SetPlotType('points'); $plot->SetYTickPos('none'); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetPlotAreaWorld(80); $plot->DrawGraph();
{ $n = count($row); $p = $k * ($n - 1); if ($p == (int) $p) { return $row[$p]; } return ($row[(int) $p] + $row[(int) ($p + 1)]) / 2; } # Convert the experimental results to a PHPlot data array. function reduce_data($results) { $data = array(); foreach ($results as $label => $row) { $n_samples = count($row); sort($row); $data[] = array("{$label}\n({$n_samples} Samples)", $row[0], kpercentile($row, 0.25), kpercentile($row, 0.5), kpercentile($row, 0.75), $row[$n_samples - 1]); // Maximum } return $data; } $plot = new PHPlot(800, 600); $plot->SetTitle('Box Plot (without outliers)'); $plot->SetDataType('text-data'); $plot->SetDataValues(reduce_data($results)); $plot->SetPlotType('boxes'); # These 2 lines make tick marks line up with text-data data points: $plot->SetXTickIncrement(1); $plot->SetXTickAnchor(0.5); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->DrawGraph();