How do I get a correct assignment of my legend when I create a Pie chart with empty values in MATLAB 7.9 (R2009b)?
2 views (last 30 days)
Show older comments
MathWorks Support Team
on 28 Jan 2010
Edited: MathWorks Support Team
on 14 Nov 2018
Pie charts with values equal to zero do not generate a patch object and then the figure contains less elements than expected leading to the wrong assignment in the legend.
figure
weights = [1 0 1 ]
pie( weights )
names = { 'blue' 'green' 'red' };
legend( names ) % <- Not good
Accepted Answer
MathWorks Support Team
on 14 Nov 2018
The ability to add a legend with correct assigned text labels is not available in MATLAB 7.9 (R2009b) when creating a PIE chart with empty values.
To work around this issue use the following command:
legend(names(weights>0))
0 Comments
More Answers (0)
See Also
Categories
Find more on Pie Charts in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!