![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1238582/image.png)
Change the position of a pie chart
조회 수: 31 (최근 30일)
이전 댓글 표시
Hi everyone,
I'd like to change the position of a pie chart from "Initial position" to "Final position" (see figure below).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1238547/image.png)
Can anyone help me?
Thank you.
Alessia
댓글 수: 0
답변 (2개)
Mathieu NOE
2022년 12월 21일
hello
try this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1238582/image.png)
X = [0.1 0.2 0.2];
subplot(1,2,1),
pie(X);
subplot(1,2,2),
pie(X);
set(gca, 'CameraViewAngleMode', 'manual', 'CameraTargetMode', 'manual', ...
'CameraPositionMode', 'manual');
ang = 3*pi/2;
set(gca, 'CameraUpVector', [sin(ang), cos(ang), 0]);
댓글 수: 3
Mathieu NOE
2022년 12월 22일
My pleasure !
If my submission fullfills your request, do you mind accepting it ?
tx
Mathieu NOE
2023년 1월 31일
hello again
If my submission fullfills your request, do you mind accepting it ?
tx
Adam Danz
2022년 12월 21일
편집: Adam Danz
2022년 12월 22일
The text label alignment needs updated since the initial alignment is designed to be to the left of the pie segments but after rotation, the labels should be centered above the segments. The text alignment adjustment is fairly easy for this example but if the pie chart contained all segements around the circle, a bit more work would be needed to assign the best alignment property values.
% Create initial pie chart
ax = axes();
h = pie([.167 .167 .167]);
% rotate 90 deg clockwise
ang = -90; % angle of rotation, degrees, negative is clockwise
tform = hgtransform('Parent',ax);
set(h, 'Parent', tform)
Rz = makehgtform('zrotate',ang*pi/180);
set(tform,'Matrix',Rz)
% Adjust text label alignment
tobj = findobj(h,'type','text');
set(tobj, 'VerticalAlignment', 'Bottom', 'HorizontalAlignment', 'Center')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Pie Charts에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!