How can I have text labels inside a pie and percentages outside the pie chart?
16 ビュー (過去 30 日間)
古いコメントを表示
How can I have text labels inside a pie and percentages outside the pie chart?
thanks in advance for any tips
0 件のコメント
採用された回答
Paulo Silva
2011 年 2 月 24 日
Here's a sneaky way to have what you want, at least with version 2008b there's the only way.
edit pie
go to line 91 of the pie.m
replace the line with the code inside=0; by this
global inside %so we can access the variable outside the function
try %this is needed to keep the function working just like before
inside==0; %without giving errors when there's no value assigned for
catch %the variable inside, the default value is zero just like before
inside=0;
end
Save pie.m
Now to try it do this example
clf
global inside %access the same variable as the one of the function
inside=0; %make it 0 to draw the percentages outside
x = [1 3 0.5 2.5 2];
explode = [0 1 0 0 0];
%labels={'1','2','3','4','5'}; %in case you want to override auto %
%pie(x,explode,labels) %use your own percentage labels
pie(x,explode); % draws the pie with auto percentage labels
hold on
inside=1; %now make it 1 so we can put labels inside
labels={'one','two','three','four','five'};
pie(x,explode,labels)
colormap jet
2 件のコメント
Paulo Silva
2011 年 2 月 24 日
You can also add FontColor and FontSize to the text(... in pie.m and make their values global (the same way as we did with the inside value) so you can have more control on the text, there's also the distance from the centre of the pie.
The only problem I see with pie is that the text from the previous patch gets under the next patch, that's probably the reason they didn't allow more control over the pie text yet.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!