Is it possible to have a zero value in the pie-chart data in MATLAB 7.6 (R2008a)?

23 views (last 30 days)
When plotting a pie-chart with any one of the data values as zero and a user-defined colormap,unexpected colors are skipped. I also get a warning message
"Warning: Ignoring non-positive data in pie chart."
With first value as 0, it skips green(second value on colormap)
Dat = [0 10 20 40]
t1col = [1 0 0]; %red
t2col = [0 1 0]; %green
t3col = [0 0 1]; %blue
t4col = [1 0 1]; %magenta
tilecolor = [t1col; t2col; t3col; t4col];
pie(Dat)
colormap(tilecolor)
With second value as 0, it skips green again
dat = [5 0 20 40]
t1col = [1 0 0]; %red
t2col = [0 1 0]; %green
t3col = [0 0 1]; %blue
t4col = [1 0 1]; %magenta
tilecolor = [t1col; t2col; t3col; t4col];
pie(dat)
colormap(tilecolor)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The ability to handle zero values in pie-chart is not available in MATLAB 7.6 (R2008a).
To work around this issue, use the attached function pie_modified(dat,tilecolor)
where variable 'Dat' is the data values for the pie chart and variable 'tilecolor' is the colormap for it. For example:
Dat = [0 10 20 40]
t1col = [1 0 0]; %red
t2col = [0 1 0]; %green
t3col = [0 0 1]; %blue
t4col = [1 0 1]; %magenta
tilecolor = [t1col; t2col; t3col; t4col];
pie_modified(Dat,tilecolor)

More Answers (2)

Tasnuba Siddiqui
Tasnuba Siddiqui on 4 Nov 2017
Edited: Walter Roberson on 5 Nov 2017
rr = [9 1 0 3 4]; % Data
labels = {'M', 'T', 'W', 'TH', 'F'}
z =(rr == 0); % Logical Array
tt = z*realmin; % Minimum No multiplied
rr = rr + tt; % Added
phr = pie (rr);
colormap([0 1 0; %// green
.5 .5 .5; %// grey
0 0 1; %// blue
1 0 1; %// magenta
1 0 0]) %// red
hText = findobj(phr,'Type','text'); % text object handles
percentValues = get(hText,'String'); % percent values
combinedtxt = strcat(labels,percentValues); % strings and percent values
hText(1).String = combinedtxt(1);
hText(2).String = combinedtxt(2);
hText(3).String = combinedtxt(3);
hText(4).String = combinedtxt(4);
hText(5).String = combinedtxt(5);
It worked for me.

KAE
KAE on 6 Nov 2019
If you are doing this to plot a pie which is missing a slice, see here ('Partial Pie').

Tags

No tags entered yet.

Products


Release

R2008a

Community Treasure Hunt

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

Start Hunting!

Translated by