Legend for tiled donut charts
조회 수: 6 (최근 30일)
이전 댓글 표시
I have a 2x3 tiled layout.
In the first row, I put three donut charts (one per each "cell"). The figure is attached.
What I want to do is to put a unique legend for them in the whole second row. I saw that this is possible for other types of charts and interesting options were suggested to other users. The main problem is that the properties for the legend of donut charts are very limited.
Suggestions?
Thank you!

댓글 수: 0
채택된 답변
Voss
2025년 1월 28일
Here's something that may help.
n = 3;
data = rand(10,n);
f = figure();
tl = tiledlayout(2,n);
d = gobjects(n,1);
for ii = 1:n
nexttile(tl)
d(ii) = donutchart(data(:,ii));
end
tl = tiledlayout(tl,1,1);
tl.Layout.Tile = n+1;
tl.Layout.TileSpan = [1,n];
ax = nexttile(tl);
ax.Visible = 'off';
c = d(1).ColorOrder;
nc = size(c,1);
nd = numel(d(1).Data);
c = repmat(c,ceil(nd/nc),1);
p = cellfun(@(x)patch(ax,NaN,NaN,x),num2cell(c(1:nd,:),2));
set(p,'FaceAlpha',d(1).FaceAlpha);
d(1).LabelsMode = 'manual';
d(1).Names = "slice "+(1:nd);
legend(p,d(1).Names,'Orientation','horizontal','NumColumns',ceil(nd/2));
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
