Pie chart label overlapping

83 visualizaciones (últimos 30 días)
Eugen Syrkin
Eugen Syrkin el 28 de Abr. de 2020
Comentada: Giuseppe Degan Di Dieco el 24 de Mayo de 2021
Hey guys so I have a pie chart with labels like 1%,2% <1% and because there are 100 values it overlaps quite a lot.
I am able to remove all labels with delete(findobj(p,'Type','Text'))
Is there any way to remove just the ones with <1% or somehow group the labels together?

Respuesta aceptada

Adam Danz
Adam Danz el 28 de Abr. de 2020
Editada: Adam Danz el 29 de Abr. de 2020
Use the pie() output handle to obtain the text objects.
h = pie(. . .);
th = findobj(h,'Type','Text'); % text handles
Determine which text strings begin with "<"
isSmall = startsWith({th.String}, '<'); % r2016b or later
% isSmall = ~cellfun(@isempty, regexp({th.String},'^<')); % any matlab release
Either delete the text objects or replace their String values with empties.
delete(th(isSmall));
%or
set(th(isSmall),'String', '')
Demo:
h = pie(sort([linspace(0,1,20),linspace(.5,2,10),linspace(1,10,20)]));
  1 comentario
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco el 24 de Mayo de 2021
Dear Adam,
you're awesome, your help was so precious.
Thanks, best.

Iniciar sesión para comentar.

Más respuestas (1)

Toder
Toder el 28 de Abr. de 2020
Editada: Toder el 28 de Abr. de 2020
Following the documentation for pie chart labels at https://www.mathworks.com/help/matlab/creating_plots/customize-pie-chart-labels.html, we can get the labels. Then a simple for loop can remove the ones you don't want.
x = [0.1 50 50];
p = pie(x);
pText = findobj(p,'Type','text');
for i=1:length(x)
if strcmp(pText(i).String,'< 1%')
pText(i).String = '';
end
end
  1 comentario
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco el 24 de Mayo de 2021
Hi Toder,
your tip is brilliant too.
Thanks for your help, and best!

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by