Add Legend to Pie Chart

This example shows how to add a legend to a pie chart that displays a description for each slice.

Define x and create a pie chart.

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

Specify the description for each pie slice in the cell array labels.

labels = {'Product A','Product B','Product C'};

Display a horizontal legend below the pie chart. Pass the descriptions contained in labels to the legend function. Set the legend's Location property to 'southoutside' and its Orientation property to 'horizontal'.

legend(labels,'Location','southoutside','Orientation','horizontal')

The graph contains a pie chart and a horizontal legend with descriptions for each pie slice.

See Also

|

Related Examples

Was this topic helpful?