Pie chart color assignment

조회 수: 7 (최근 30일)
Sordin
Sordin 2018년 6월 21일
댓글: Sordin 2018년 6월 21일
I am trying to make a pie chart of two quantities. Using a colormap, I have assigned two different colours to each of the quantities – one is green and the other one red.
In one of the charts the first quantity is at 100%, while in the other chart the second quantity is at 100%. So one chart has to be entirely red, and the other one entirely green. However, both charts always appear with the same colour:
And here is what I am trying to obtain:
So what is wrong here and how can we fix the problem?
Here is my code:
subplot(211)
x=[1,0];
pie(x)
colormap([0 0.70 0; 1 0.1 0]);
subplot(212)
x=[0,1];
pie(x)
Any help is greatly appreciated.

채택된 답변

Jeffrey Eymer
Jeffrey Eymer 2018년 6월 21일
Pie ignores non-positive values. Therefore, both arrays you declare are treated as the same to pie, and are interpreted as [1]. This is why you see that pie is treating both inputs as being 100% red.
One workaround you could use would be to call colormap twice, once after each plot. This would give you the desired colors. Other than that, it seems you would need to input some non-zero information into the pie chart. Otherwise, they will be ignored.
  댓글 수: 1
Sordin
Sordin 2018년 6월 21일
But calling it twice will not solve the problem because each time the last colormap will apply to the whole figure. Is there a way that each subplot can have its own separate colormap?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Pie Charts에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by