Legend for tiled donut charts
5 ビュー (過去 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!
