필터 지우기
필터 지우기

Pie Chart Percentages Of Each Section

조회 수: 1 (최근 30일)
Ogen
Ogen 2016년 3월 7일
댓글: Ogen 2016년 3월 7일
Hello everyone I have plotted a pie chart of blast energy, thermal energy and nuclear radiation (see attachment). I want to display the percentage each specific section contributes to the overall energy (% each section of pie contributes to whole pie). Any help to edit the code to this would be greatly appreciated. Thanks.
if true
% code
kt = 'Please enter the yield in kilotonnes you wish to test: ';
kt = input(kt);
Ktjoules=(1*10^12);
TotalEnergy=kt*Ktjoules;
Blastenergy=(kt*Ktjoules)/(100)*(50);
ThermalEnergy=(kt*Ktjoules)/(100)*(35);
NuclearRadiation=(kt*Ktjoules)/(100)*(15);
title('Graph to show Blast Engergy, Thermal Energy and Nuclear Radiation in KiloTonnes')
x = [Blastenergy, ThermalEnergy, NuclearRadiation];
labels = {'Blast Energy','Thermal Energy','Nuclear Radiation'};
figure
pie3(x,labels)
view([-65, 35])
end
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2016년 3월 7일
Jack - there is no attachment. Once you have chosen the file, please press the Attach File button.
Ogen
Ogen 2016년 3월 7일
Thanks Geoff, think its there now

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2016년 3월 7일
Jack - if you wish to include the pie char percentages for each slice (which will be fixed at 50, 35 and 15 with your above code), then you could do
labels = {sprintf('Blast Energy (%.02f%%)',Blastenergy/TotalEnergy*100),...
sprintf('Thermal Energy (%.02f%%)',ThermalEnergy/TotalEnergy*100),...
sprintf('Nuclear Radiation (%.02f%%)',NuclearRadiation/TotalEnergy*100)};
figure
pie3(x,labels)
title('Graph to show Blast Engergy, Thermal Energy and Nuclear Radiation in KiloTonnes')
view([-65, 35])
Note that the title is called after we have created the figure. Try the above and see what happens!
  댓글 수: 5
Geoff Hayes
Geoff Hayes 2016년 3월 7일
Jack - yes, subplot refers to the other axes within your figure. For example, suppose we run the above code and we want to put the pie chart in the left-most axes. Prior to calling pie3 we do
hLeftAxes = subplot(1,2,1);
pie3(hLeftAxes,x,labels);
title(hLeftAxes,'Graph to show Blast Energy, Thermal Energy and Nuclear Radiation in KiloTonnes');
view(hLeftAxes,[-65, 35]);
The call to subplot returns a handle to the axes. We then pass that handle into pie3 to ensure that the pie chart is drawn there. (Same for title and view - we pass the handle to the axes that we wish to update.)
Ogen
Ogen 2016년 3월 7일
That's brilliant, thanks for your time

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by