How to insert both value and percentage in pie chart?

36 ビュー (過去 30 日間)
Tony Castillo
Tony Castillo 2022 年 8 月 2 日
コメント済み: Tony Castillo 2022 年 8 月 3 日
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 Center および File ExchangePie Charts についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by