pie — Create pie charts in MATLAB and RunMat.

pie creates part-to-whole charts from numeric slice values. Handle behavior, explode controls, and labeling follow MATLAB semantics.

Syntax

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

Inputs

NameTypeRequiredDefaultDescription
XNumericArrayYesSlice values.
explodeNumericArrayYesSlice explode mask (nonzero elements explode).
labelsAnyYesLabel list or label format string.
axNumericScalarYesTarget axes handle.
dataAnyVariadicPie data arguments.

Returns

NameTypeDescription
hNumericScalarHandle to the pie chart.

Errors

IdentifierWhenMessage
RunMat:pie:InvalidArgumentPie values, explode vectors, or labels are malformed or incompatible.pie: invalid argument
RunMat:pie:InternalInternal render preparation fails.pie: internal operation failed

How pie works

  • Slice values determine the relative angular extent of each wedge.
  • Explode-style workflows and slice labels are part of the pie rendering path.
  • The returned value is a pie-handle object participating in the same broader plotting handle model used across the plotting stack.
  • Pie labels and overlay semantics survive replay/export because they are part of the shared event/scene path.
  • Pie charts are especially useful as the part-to-whole complement to bar and histogram-style quantitative plots.

Examples

Create a basic pie chart

pie([2 3 5]);

Create an exploded pie chart

values = [4 2 3 1];
explode = [1 0 1 0];
pie(values, explode);

Use labels for slice names

values = [5 3 2];
labels = {'compute', 'io', 'render'};
pie(values, labels);

Budget allocation

values = [35 25 20 12 8];
labels = {'Engineering', 'Marketing', 'Operations', 'R&D', 'Admin'};
explode = [1 0 0 0 0];

pie(values, explode);
title('Annual Budget Allocation');
legend(labels);
Expected output:
Budget allocation

Using pie with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how pie changes the result.

Run a small pie example, explain the result, then change one input and compare the output.

FAQ

How do I explode specific slices out of the pie?

Pass an explode vector the same length as your values. A 1 pulls that slice outward; a 0 keeps it flush.

pie([4 2 3 1], [0 1 0 0]);

This explodes only the second slice. You can explode multiple slices by setting more entries to 1.

How do I add percentage labels to slices?

By default, pie displays percentage labels on each slice. To use custom labels instead, pass a cell array of strings as the second argument.

pie([5 3 2], {'compute 50%', 'io 30%', 'render 20%'});

If you want no labels at all, pass empty strings for each slice.

When should I use a pie chart vs a bar chart?

Pie charts work well when you have a small number of slices (2–5) and the point is to show each slice's share of a whole. Once you go beyond ~6 slices or need to compare absolute values across categories, bar is almost always clearer—humans are better at comparing lengths than angles. If two slices are close in size and the difference matters, use bar.

2D Charts

area · bar · errorbar · heatmap · hist · histogram · loglog · plot · scatter · semilogx · semilogy · stairs · stem

3D & Surface

contour · contour3 · contourf · mesh · meshc · plot3 · quiver · scatter3 · surf · surfc

Images

image · imagesc · imshow

Axes & Layout

axis · box · grid · sgtitle · subplot · title · view · zlabel

Appearance

colorbar · colormap · legend · shading

Handle Access

gca · gcf · get · set

Other

cla · clf · figure · fill3 · hold · patch · polarplot · print · suptitle · xline · yline

More plotting resources

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how pie is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.