How to insert both value and percentage in pie chart?

40 次查看(过去 30 天)
Dear all,
I just want to know how to insert in the same pie chart the values that comprise the already presented percentage?
This is the code
figure
xe=[5, 20, 15];
explode=[ 1 0 1];
pe=pie(xe, explode);
%%%% tagging
pText = findobj(pe,'Type','text');
percentValues = get(pText,'String');
txt = {'Geothermal: '; 'PV: '; 'EVs: '};
combinedtxt = strcat(txt,percentValues);
%%%%Set text
pText(1).String = combinedtxt(1);
pText(2).String = combinedtxt(2);
pText(3).String = combinedtxt(3);

采纳的回答

dpb
dpb 2022-8-2
That's another terrible user interface/oversight to go along with bar -- hadn't ever used it in MATLAB before; pie charts just are a format I used rarely, if ever...anyways, that aside you've got to build them yourselves it seems, but isn't too difficult, just annoying--
labels=compose('%s: %d (%0.1f%%)',string(txt),xe(:),100*xe(:)/sum(xe));
hP=pie(xe,explode,labels)
works -- you might want to try
labels=compose('%s: %d \n(%0.1f%%)',string(txt),xe(:),100*xe(:)/sum(xe));
and 'spearmint about alternate formatting.
NB: You'll have better luck and the above assumes the trailing ":" and blanks have been removed from the variable names/section names.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Pie Charts 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by