【问题标题】:Print Pie Chart percentages in Matlab in Rational Format在 Matlab 中以 Rational 格式打印饼图百分比
【发布时间】:2020-06-20 15:14:54
【问题描述】:

在 Matlab 饼图中,在分类数据中,结果以百分比格式打印。 有没有办法以合理的形式改变这种格式?例如。而不是一组 12 个数据中的 50%,而是打印 6/12。在工作区中输入长格式格式并不能解决这个问题。

更好的是,我们可以写出两个结果,即 50% (6/12)。

工作示例:

X = categorical({'North','South','North','East','South','West'});
pie(X)

【问题讨论】:

    标签: matlab plot matlab-figure pie-chart


    【解决方案1】:

    您可以使用countcats 获取出现次数并手动制作标签:

    N = numel(X);         % total number of items
    n = countcats(X);     % number of items per category
    cats = categories(X); % unique categories in same order as countcats
    labels = arrayfun( @(ii) sprintf('%s (%.0f/%.0f)', cats{ii}, n(ii), N), ...
                       1:numel(n), 'uni', 0 );
    

    然后制作你的饼图

    pie(n, labels)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-10
      • 2016-07-24
      • 2023-01-11
      • 2022-06-18
      相关资源
      最近更新 更多