www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/AddLegendToPieChartExample.m

    %% Add Legend to Pie Chart
% This example shows how to add a legend to a pie chart that displays a
% description for each slice. 

% Copyright 2015 The MathWorks, Inc.


%%
% 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.