필터 지우기
필터 지우기

Filling pie graph partitions without the Pie command

조회 수: 3 (최근 30일)
Daniel
Daniel 2019년 12월 26일
답변: Chidvi Modala 2019년 12월 30일
Hi everyone,
I have created a code which basically produces a pie graph between two rings, but I am stuck at filling my partitions with different colors. Does anyone have an Idea to how to solve this? I tried using patch and fill but I can't seem to get them to follow the circles (they just connect the endlines of the partition with a line, not following the circle)
  댓글 수: 2
Sergey Kasyanov
Sergey Kasyanov 2019년 12월 27일
I will try to complete your code if you attache it or I will write my own code for plotiing a pie with filled sectors.
Daniel
Daniel 2019년 12월 27일
I have found a solution which does the job but isn't very nice. It's basically plotting a lot of fat lines to fill the circle.
Thanks anyways for the quick reply!

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

답변 (1개)

Chidvi Modala
Chidvi Modala 2019년 12월 30일
You can make you of following code
function pie_chart
% Define quadrants and color
r1 = 1; % Outer radius
r = 0.5; % Inner radius
v = [5 15 25 20 35];
C = {'r' 'b' 'm' 'c' 'g'};
theta= 0:0.01:2*pi;
idx_spokes = round( [1 cumsum(v)/100*length(theta) ] ) ; % find the indices of the spokes
for k=1:length(idx_spokes)-1
t = theta( idx_spokes(k):idx_spokes(k+1) ) ; % Theta for Inner ring
si=theta( idx_spokes(k)); % Start index of polygon to be filled
t1 = theta( idx_spokes(k+1):-1:idx_spokes(k) ) ; % Theta for Outer ring
x=[r*cos(t) r1*cos(t1) r*cos(si)];
y=[r*sin(t) r1*sin(t1) r*sin(si)];
plot(x,y);
hold on
fill(x,y, C{k} );
end
axis square
axis on

카테고리

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