Hey all, I want to know is possible to have a pie chart with 5 pies so that I can change the color of each pie that I want? Just like this:
I don't have any data sets, in this case, I just want pie chart with 5 equal parts with ability to change colors.
Please let me know is this possible to do this in Matlab?
Best Regards.

 채택된 답변

Tommy
Tommy 2020년 4월 11일

1 개 추천

One option:
p = pie(ones(1,5)); % create a pie chart with 5 equal slices
t = p(2:2:end); % get the handles to the text labels
p = p(1:2:end); % get the handles to the patches
delete(t) % delete the text labels
p(2).FaceColor = 'g'; % change the color of the second patch to green

댓글 수: 2

BN
BN 2020년 4월 11일
Thank you so much !
Les Beckham
Les Beckham 2020년 4월 11일
FYI
If you prefer lighter colors like in the example in your question, you can experiment with the FaceAlpha property. For example, to make the green slice in Tommy's solution lighter, you could do this:
p(2).FaceAlpha = 0.3;

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

추가 답변 (1개)

Geoff Hayes
Geoff Hayes 2020년 4월 11일

1 개 추천

Behzad - yes, you can change the colours of each piece of the pie. To generate a pie chart with five equal pieces, just do
hPatchAndTextObjects = pie(ones(1,5))
The hPatchAndTextObjects is an array of handles to the patch and text graphics objects. On my version of MATLAB, the ordering is patch object, text object, patch object, text object, etc. To change the colour of the first patch object, just do
set(hPatchAndTextObjects(1), 'FaceColor', [1 1 0])
which will set the colour to yellow.

댓글 수: 2

BN
BN 2020년 4월 13일
Thank you so much +1
Hi guys,
hope you're still reading these days.
@Geoff Hayes's tip is a very good one, so you can set up all other patches' color with a for loop.
I posted the code too, it may be of help.
Thanks for maintaining the community, and best.
ax3 = nexttile;
pRoadRailway = pie(ax3, heightsRoadRailway, labelsRoadRailway);
legend(legendRoadRailway, 'Location', 'southoutside');
myColors = [0 0.4470 0.7410; ...
0.8500 0.3250 0.0980;...
0.9290 0.6940 0.1250];
%
for i = 1:2:4
set(pRoadRailway(i), 'FaceColor', myColors(i, :))
end

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

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

질문:

BN
2020년 4월 11일

댓글:

2021년 6월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by