Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# pie

## Syntax

pie(X)
pie(X,explode)
pie(...,labels)
pie(axes_handle,...)
h = pie(...)

## Description

pie(X) draws a pie chart using the data in X. Each element in X is represented as a slice in the pie chart.

• If sum(X) ≤ 1, then the values in X directly specify the area of the pie slices. pie draws only a partial pie if sum(X) < 1.

• If the sum of the elements in X is greater than one, then pie normalizes the values by X/sum(X) to determine the area of each slice of the pie.

pie(X,explode) offsets a slice from the pie. explode is a vector or matrix of zeros and nonzeros that correspond to X. A nonzero value offsets the corresponding slice from the center of the pie chart, so that X(i,j) is offset from the center if explode(i,j) is nonzero. explode must be the same size as X.

pie(...,labels) specifies text labels for the slices. The number of labels must equal the number of elements in X.

pie(axes_handle,...) plots into the axes with the handle axes_handle instead of into the current axes (gca).

h = pie(...) returns a vector of handles to patch and text graphics objects.

## Examples

expand all

### Create Pie Chart

Create a pie chart of vector x.

```x = [1,3,0.5,2.5,2];
figure
pie(x)
```

To offset the second and fourth pie slices, set the corresponding explode elements to 1.

```explode = [0,1,0,1,0];
figure
pie(x,explode)
```

### Specify Text Labels for Pie Chart

Specify the text labels for a pie chart.

```x = 1:3;
labels = {'Taxes','Expenses','Profit'};

figure
pie(x,labels)
```

### Remove Piece From Pie Chart

Create a pie chart of x.

```x = [0.19,0.22,0.41];
figure
pie(x)
```

Since the sum of the elements in x is less than 1, pie draws a partial pie.