Decimals selection in pie charts
7 views (last 30 days)
Show older comments
Hi! I'm trying to choose the number of decimals in the chart, but couldn't find anything in the documentation. Does anyone know how to do it? For example, how to do it on the following simple case? It always returns the approximation 10% and 90%, but I need an higher precision: 10.1% and 89.9%. Thank you!
x = [0.101 .899];
pie(x)
0 Comments
Accepted Answer
Walter Roberson
on 11 Oct 2017
The code internally uses an integer format for the values multiplied by 100%, so there is no way to tell it to just use more decimal places.
However, you can pass a cell array of character vectors as the second element of pie(), and those will be used as the labels. You can construct that cell array of character vectors.
percent = x(:) ./ sum(x(:)) * 100;
labels = cellstr( numestr( percent, '%.1f%%' ) ); %relies on percent being a column vector
pie(x, labels);
2 Comments
Mats Burgmans
on 23 May 2018
I get this error when using your code: Undefined function or variable 'numestr'.
More Answers (0)
See Also
Categories
Find more on Pie Charts in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!