How to insert both value and percentage in pie chart?

조회 수: 32 (최근 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 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