5.51. Example - Box Plot with Outliers and Styles
Prev | Chapter 5. PHPlot Examples | Next

## 5.51. Example - Box Plot with Outliers and Styles

This is a box plot (plot type boxes). Unlike the previous example (Section 5.50, “Example - Box Plot with Data Reduction”) the data array is already processed, and includes the 5 values that make up each row for a box plot (`Ymin, YQ1, Ymid, YQ3, Ymax`) and some additional outlier points. This example also shows how colors and line styles can be applied to a box plot.

Note: Box plots were added in PHPlot-6.1.0.

Example 5.51. Box Plot with Outliers and Styles

    <?php
    # PHPlot Example - Box Plot with outliers and line styles
    require_once 'phplot.php';

    # Data array: each row is (label, X, Ymin, YQ1, Ymid, YQ3, Ymax, [Youtlier...])
    $data = array(
        array('', 1,  10, 15, 20, 25, 30),
        array('', 2,  12, 14, 18, 20, 24,  6, 8, 28),
        array('', 3,   5, 11, 19, 28, 35),
        array('', 4,  14, 17, 21, 26, 28,  9, 12, 35, 32),
        array('', 5,  12, 15, 22, 27, 30),
        array('', 6,  15, 18, 20, 22, 26, 12),
        array('', 7,  10, 15, 21, 26, 28, 32),
        array('', 8,  11, 15, 20, 24, 27, 6, 8),
        array('', 9,  10, 15, 19, 22, 26, 4, 34),
    );

    $plot = new PHPlot(800, 600);
    $plot->SetTitle('Box Plot with outliers and styles');
    $plot->SetDataType('data-data');
    $plot->SetDataValues($data);
    $plot->SetPlotType('boxes');
    $plot->SetImageBorderType('plain'); // Improves presentation in the manual

    # Use dashed lines for the upper and lower whiskers:
    $plot->SetLineStyles('dashed');
    # Make the box and belt use a thicker line:
    $plot->SetLineWidths(array(3, 3, 1));
    # Make the outliers red, and everything else blue:
    $plot->SetDataColors(array('blue', 'blue', 'red', 'blue'));
    # Draw the outliers using a "star":
    $plot->SetPointShapes('star');

    $plot->DrawGraph();

Prev | Up | Next
5.50. Example - Box Plot with Data Reduction | Home | Chapter 6. PHPlot Functions By Category