increase the precision of pie chart labels

17 ビュー (過去 30 日間)
sa ab
sa ab 2020 年 4 月 9 日
回答済み: Vinai Datta Thatiparthi 2020 年 4 月 13 日
Hi!
I am trying to create a pie chart and increase the precision of the percentage to two decimals but it gives an error even for the simplist example as below.
X = [1/3 2/3];
pie(X,'%.3f%%')
Error using pie (line 71)
X and EXPLODE must be the same length.
line 71 [[sliceCounts, explode, labels, displayNames] = parseArgs(args, nargs);]
Thank you for teaching me the right one!
  3 件のコメント
sa ab
sa ab 2020 年 4 月 9 日
Hi Ameer!
Thank you for support.
You are right it should be very simple but I do not know why it does not work.
Here is the result of which pie:
/Applications/MATLAB_R2019b.app/toolbox/matlab/specgraph/pie.m
It is R2019b.
This is what you suggested:
>> pie(x)
>> X = [1/3 2/3];
pie(X, "%.3f%%")
Error using pie (line 71)
Cell array of character vectors must be the same length as X.
Thank you!
Ameer Hamza
Ameer Hamza 2020 年 4 月 10 日
I am using R2020a, so I cannot try it on R2019b. But from the output of 'which pie' and the error message, I couldn't figure out the issue. The definition of the pie function seems correct.

サインインしてコメントする。

回答 (1 件)

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi 2020 年 4 月 13 日
Hello,
MATLAB R2020a has this new feature that allows the user to specify a numeric format for the percentage labels on a pie chart. For example, you can specify the number of decimal places or significant digits to display in the label. Older versions (R19b and earlier) do not support this feature, and you will be prompted with a length-mismatch error.
Please update MATLAB to the latest version i.e. R2020a to be able to use the function "pie" in the way that you mentioned.
Additionally, these links can be useful to you -
  • Documentation of pie: Latest changes to "labels" input argument that allows you to specify its numeric format
  • Release Notes: All the latest updates/features to MATLAB
Hope this helps!

カテゴリ

Help Center および File ExchangePie Charts についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by