How to insert both value and percentage in pie chart?
40 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tony Castillo
am 2 Aug. 2022
Kommentiert: Tony Castillo
am 3 Aug. 2022
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);
0 Kommentare
Akzeptierte Antwort
dpb
am 2 Aug. 2022
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Pie Charts finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!