3.4. PHPlot Plot Types
Prev | Chapter 3. PHPlot Concepts | Next

## 3.4. PHPlot Plot Types

This section describes the PHPlot plot types and their individual data type requirements.

Plot types determine the overall look of the graphical representation of the data values. To select the plot type, use SetPlotType. The following plot types are available:

Plot Type | Description
--- | ---
area | Filled areas between lines. Also known as 'cumulative line plot' or 'component line plot'.
bars | Filled bars with optional 3-D look, multiple datasets are offset
linepoints | Lines between points, a marker at each point, optional error bars
lines | Straight lines between data points, optional error bars
pie | Pie chart with or without 3-D affects
points | Draws a marker at each data point, optional error bars
squared | Stepped lines
stackedarea | Filled areas between lines, with multiple data sets accumulated
stackedbars | Filled bars with optional 3-D look, multiple data sets are accumulated and the sum is graphed
thinbarline | Vertical lines from X axis up. Also known as impulse.

### 3.4.1. Plot Type: area (Area Plot)

This plot type draws filled areas between lines. This is often called a 'cumulative line plot' or 'component line plot'. Each data set (set of corresponding Y values from each record in the data array) is plotted in order, with the area between each line and the next line filled solid. The area between the last line and the X axis is also filled. The data must be arranged so the values are (generally) decreasing within each row, because later drawn filled areas will cover previously drawn areas.

This plot type works with data types 'text-data' and 'data-data' (see Section 3.3.1, “Available Data Types”). For 'text-data', the data X values are assumed to be at 0.5+N for N=0,1,2...

This plot type uses the absolute value of each supplied Y, because negative values do not make sense here. Missing values are taken as zero. All records in the data array must have the same number of Y values.

The areas are filled with colors as set with SetDataColors.

An example of this plot type can be seen in Section 5.3, “Example - Area Plot”.

### 3.4.2. Plot Type: bars (Bar Graph)

This plot type draws a bar chart, with filled rectangles centered on the X values. The rectangles can have a 3-D look or be flat with a border. Multiple data-set plots work, with each one producing a set of bars offset from the previous set.

This plot type only works with data type 'text-data' (see Section 3.3.1, “Available Data Types”). The data X values are assumed to be at 0.5+N for N=0,1,2...

If shading is on with SetShading (default is on with value 5 pixels), then the bars have a 3-D look. If shading is off (`SetShading(0)`), the bars are flat rectangles with borders. The filled rectangle color is set with SetDataColors. The border color (if shading is off) can be set with SetDataBorderColors.

Examples of this plot type can be seen in Section 5.4, “Example - Bar Chart”, Section 5.5, “Example - Unshaded Bar Chart”, Section 5.6, “Example - Bar Chart, Label Options”, and Section 5.19, “Example - Bar Chart with Data Labels”.

### 3.4.3. Plot Type: linepoints (Lines and Points)

This plot type draws a line graph with a markers at each point, thus combining the 'line' and 'point' plot types.

This plot type works with data types 'text-data' and 'data-data' (see Section 3.3.1, “Available Data Types”). For 'text-data', the data X values are assumed to be at 0.5+N for N=0,1,2... It also works with 'data-data-error' for error bars.

Line and marker colors for each line are set with SetDataColors. Marker styles for each line are set with SetPointShapes. Marker sizes for each line are set with SetPointSizes. Line widths for each line are set with SetLineWidths. Line styles (solid or dashed) for each line are set with SetLineStyles.

You can also suppress the line, or the markers, for individual data sets in a graph. This allows you combine points-only, lines-only, and line/points plots. Refer to SetLineStyles and SetPointShapes for details.

For error-bar plots with data type 'data-data-error' only: Error bar colors for each line are set with SetErrorBarColors. Error bar shape (tee or line) is set with SetErrorBarShape. If tee-shaped error bars are used, the width of the upper and lower 'tee' is set with SetErrorBarSize. Error bar line width is set with SetErrorBarLineWidth.

An example of this plot type can be seen in Section 5.7, “Example - Line/Point Plot, Point Shapes”.

### 3.4.4. Plot Type: lines (Lines Graph)

This plot type simply draws a line from each point to the next.

This plot type works with data types 'text-data' and 'data-data' (see Section 3.3.1, “Available Data Types”). For 'text-data', the data X values are assumed to be at 0.5+N for N=0,1,2... It also works with 'data-data-error' for error bars.

Line colors for each line are set with SetDataColors. Line widths for each line are set with SetLineWidths. Line styles (solid or dashed) for each line are set with SetLineStyles.

For error-bar plots with data type 'data-data-error' only: Error bar colors for each line are set with SetErrorBarColors. Error bar shape (tee or line) is set with SetErrorBarShape. If tee-shaped error bars are used, the width of the upper and lower 'tee' is set with SetErrorBarSize. Error bar line width is set with SetErrorBarLineWidth.

Examples of this plot type can be seen in Section 5.1, “Example - Line Plot” and Section 5.2, “Example - Line Plot: Functions”.

### 3.4.5. Plot Type: pie (Pie Chart)

This plot type draws pie charts. The pie chart can have a 3-D look or be drawn flat. The first pie segment starts at 0 degrees (East, or 3:00PM) and they go around the pie in a counter-clockwise direction. Each segment is labeled with its percentage.

This plot type works with data types 'text-data', 'data-data', and 'text-data-single' (see Section 3.3.1, “Available Data Types”). Data arrays for pie charts are handled differently than with other plot types, so the data types are described in more detail below.

If shading is on with SetShading (default is on with value 5 pixels), then the pie chart has a 3-D look. If shading is off (`SetShading(0)`), the pie chart is drawn flat (circular rather than oval). The position of the segment percentage labels is set with SetLabelScalePosition.

Examples of this plot type can be seen in Section 5.8, “Example - Pie Chart, text-data-single” (text-data-single), Section 5.9, “Example - Pie Chart, text-data” (text-data), and Section 5.10, “Example - Pie Chart, flat with options” (unshaded).

#### 3.4.5.1. Pie Chart with data type: 'text-data-single'

The data array for pie charts with 'text-data-single' data type is structured as follows. Each record in the data array represents a pie segment. The record is an array of 2 elements: label and value, but the label is ignored. The value sets the relative size of a pie segment. PHPlot totals up the values and computes the relative size of each segment.

For example:

    $data = array(array('', 1), array('',4), array('',5));

This makes a pie chart with 3 segments, with sizes 10%, 40%, and 50%.

#### 3.4.5.2. Pie Chart with data type: 'text-data'

The data array for pie charts with 'text-data' data type is structured as follows. Each record in the data array is an array of a label followed by N data values. The label is ignored. The pie chart will be produced with N segments. The relative weight of the first segment is the sum of the first data values in each record. The relative weight of each subsequent segment is the sum of the corresponding data values in each record.

For example:

    $data = array(array('', 10, 10, 20, 10),
                  array('', 15, 10, 15, 10));

This results in 4 segments with sizes 25%, 20%, 35%, and 20%.

#### 3.4.5.3. Pie Chart with data type: 'data-data'

The data array for pie charts with 'data-data' data type is structured the same as 'text-data', except that the first two values in each record are ignored (the positions usually used for label and X value). Each element in the data array represents a record. Each record is an array of a label, X value, then N data values. The label and X value are ignored. The pie chart will be produced with N segments. The relative weight of the first segment is the sum of the first data values in each record. The relative weight of each subsequent segment is the sum of the corresponding data values in each record.

For example:

    $data = array(array('', 1, 10, 10, 20, 10),
                  array('', 2, 15, 10, 15, 10));

This results in 4 segments with sizes 25%, 20%, 35%, and 20%. The empty strings and '1' and '2' are ignored.

### 3.4.6. Plot Type: points (Styled Dot Plot)

This plot type draws a point marker at each X,Y value.

This plot type works with data types 'text-data' and 'data-data' (see Section 3.3.1, “Available Data Types”). For 'text-data', the data X values are assumed to be at 0.5+N for N=0,1,2... It also works with 'data-data-error' for points with error bars.

Marker colors for each line are set with SetDataColors. Marker styles for each line are set with SetPointShapes. Marker sizes for each line are set with SetPointSizes.

For error-bar plots with data type 'data-data-error' only: Error bar colors for each line are set with SetErrorBarColors. Error bar shape (tee or line) is set with SetErrorBarShape. If tee-shaped error bars are used, the width of the upper and lower 'tee' is set with SetErrorBarSize. Error bar line width is set with SetErrorBarLineWidth.

Examples of this plot type can be seen in Section 5.12, “Example - Points Plot / Scatterplot” (scatterplot), and Section 5.11, “Example - Points Plot with Error Bars” (with error bars).

### 3.4.7. Plot Type: squared (Step Plot)

This plot type makes stepped lines. For each point, you get a horizontal line from the previous point to the current X, then a vertical line to the current Y.

This plot type works with data types 'text-data' and 'data-data' (see Section 3.3.1, “Available Data Types”). For 'text-data', the data X values are assumed to be at 0.5+N for N=0,1,2...

Line colors per line are set with SetDataColors. Line widths per line are set with SetLineWidths. Line style (solid or dashed) per line are set with SetLineStyles.

An example of this plot type can be seen in Section 5.13, “Example - Squared Plot”.

### 3.4.8. Plot Type: stackedarea (Stacked Area Plot)

This plot type draws filled areas between lines, similar to Section 3.4.1, “Plot Type: area (Area Plot)” except the values are accumulated in the same manner as for Section 3.4.9, “Plot Type: stackedbars”. For each data set (set of corresponding Y values from each record in the data array), the area between the X axis and the first Y value is filled. The area between the first Y value and the sum of the first and second Y values is filled next, and so on. The top-most line is the sum of all the Y values for each record.

This plot type works with data types 'text-data' and 'data-data' (see Section 3.3.1, “Available Data Types”). For 'text-data', the data X values are assumed to be at 0.5+N for N=0,1,2...

This plot type uses the absolute value of each supplied Y, because negative values do not make sense here. Missing values are taken as zero. All records in the data array must have the same number of Y values.

The areas are filled with colors as set with SetDataColors. Note that data sets are processed with stacked area plots in reverse order relative to area plots. With stacked area plots, the first data set (using the first data color) will be at the bottom, but with area plots it will be at the top. Compare Section 5.3, “Example - Area Plot” and Section 5.21, “Example - Stacked Area Plot”.

An example of this plot type can be seen in Section 5.21, “Example - Stacked Area Plot”.

This plot type was added in PHPlot-5.1.1.

### 3.4.9. Plot Type: stackedbars

This plot type draws a bar chart with stacked bars centered on each X value. Each data set value contributes one segment of a stack. That is, the first data set is drawn at the X axis in the first color, then the second data set is drawn stacked above the first in the second color, etc. For this plot type, all Y data values must be greater than or equal to 0. Negative values are not supported.

This plot type only works with data type 'text-data' (see Section 3.3.1, “Available Data Types”). The data X values are assumed to be at 0.5+N for N=0,1,2...

If shading is on with SetShading (default is on with value 5 pixels), then the bars have a 3-D look. If shading is off (`SetShading(0)`), the bars are flat rectangles with borders. The filled rectangle colors for each stacked segment are set with SetDataColors. The border color (if shading is off) can be set with SetDataBorderColors.

Examples of this plot type can be seen in Section 5.14, “Example - Stacked Bars, Shaded”, Section 5.15, “Example - Stacked Bars, Unshaded”, and Section 5.20, “Example - Stacked Bars with Y Data Labels”.

### 3.4.10. Plot Type: thinbarline

This plot type draws vertical lines up from the X axis to the Y value at each point. Other implementations call this type of plot 'impulses'. Plotting multiple data sets does not work, because the lines are drawn on top of each other and only one can typically be seen.

This plot type works with data types 'text-data' and 'data-data' (see Section 3.3.1, “Available Data Types”). For 'text-data', the data X values are assumed to be at 0.5+N for N=0,1,2...

Impulse width can be controlled with SetLineWidths.

Examples of this plot type can be seen in Section 5.16, “Example - Thin Bar Line Plot” and Section 5.17, “Example - Thin Bar Line Plot, Wider Lines”.

Prev | Up | Next
3.3. PHPlot Data Types | Home | 3.5. Colors