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)
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
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))

More Answers (0)

Tags

Products


Release

R2009b

Community Treasure Hunt

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

Start Hunting!