Legend for tiled donut charts

4 visualizaciones (últimos 30 días)
Andrea Costantino
Andrea Costantino el 28 de En. de 2025
Respondida: Andrea Costantino el 29 de En. de 2025
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!

Respuesta aceptada

Voss
Voss el 28 de En. de 2025
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));

Más respuestas (1)

Andrea Costantino
Andrea Costantino el 29 de En. de 2025
It helped a lot! Thank you very much!

Categorías

Más información sobre Legend en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by