필터 지우기
필터 지우기

create empty pie chart (or not generate the graph)

조회 수: 1 (최근 30일)
Alberto Acri
Alberto Acri 2023년 12월 1일
댓글: Voss 2023년 12월 1일
Hi! I would like to create empty pie chart (I know it is not very useful).
Using 'pie' does not allow this. so I had thought of generating a circle and placing the legend on the side. Is this possible?
matrix_new = [];
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
figure
p = pie(percentages);
theta = linspace(0,2*pi,500);
line(cos(theta),sin(theta),'Color','k','LineWidth',0.6);
label_str = load("label_str.mat");
lgd.Title.String = "title";
If it's not possibile, how can I make it so that when 'matrix_new' is empty it doesn't generate the graph for me (so don't do anything)?

채택된 답변

Voss
Voss 2023년 12월 1일
Maybe something like this:
matrix_new = [];
figure
if isempty(matrix_new)
% matrix_new is empty: create the circle
theta = linspace(0,2*pi,500);
line(cos(theta),sin(theta),'Color','k','LineWidth',1);
% mimic pie() axes appearance:
axis off
axis equal
else
% matrix new is not empty: create the pie() chart
labels = matrix_new(:,1);
percentages = matrix_new(:,2);
p = pie(percentages);
end
% I'm not sure where this mat file comes from, but it should contain enough
% labels for the data in matrix_new:
label_str = load("label_str.mat");
% create the legend:
lgd = legend(label_str.label_str,'Location','EastOutside');
lgd.Title.String = "title";
  댓글 수: 2
Alberto Acri
Alberto Acri 2023년 12월 1일
yes, that's good. Can I ask if the legend can be moved a little to the left, for example?
Voss
Voss 2023년 12월 1일
Not sure about that.

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by