Add Legend to Pie Chart
This example shows how to add a legend to a pie chart that displays a description for each slice.
Definex
and create a pie chart.
x = [1,2,3]; figure pie(x)
Specify the description for each pie slice in the cell arraylabels
. Specify the descriptions in the order that you specified the data inx
.
labels = {'Product A','Product B','Product C'};
Display a horizontal legend below the pie chart. Pass the descriptions contained inlabels
to the传说
function. Set the legend'sLocation
property to'southoutside'
and itsOrientation
property to'horizontal'
.
传说(labels,'Location','southoutside','Orientation','horizontal')