频率的MATLAB条形图

h9vpoimq  于 2023-01-13  发布在  Matlab
关注(0)|答案(1)|浏览(176)

我有下面的代码,它计数的数量'否定'的每个唯一的ID。

clc
clear
close all

data = {
'vajbfch07wu11y90'  'negative'
'ekvpmhqybu920hnr'  'negative'
'eddbdv5bsqggeydq'  'negative'
'eddbdv5bsqggeydq'  'negative'
'eddbdv5bsqggeydq'  'negative'
'eddbdv5bsqggeydq'  'negative'
'eddbdv5bsqggeydq'  'negative'
'eddbdv5bsqggeydq'  'negative'
'6vmhbj7041fe7xck'  'negative'
'6vmhbj7041fe7xck'  'negative'
'6vmhbj7041fe7xck'  'negative'
'6vmhbj7041fe7xck'  'negative'
'j5d6dgzbeynyyg02'  'negative'
'j5d6dgzbeynyyg02'  'negative'
'j5d6dgzbeynyyg02'  'negative'
'v21tstcp164uya6g'  'negative'
'v21tstcp164uya6g'  'negative'
'brjmfpunj00rn92c'  'negative'
'brjmfpunj00rn92c'  'negative'
'mb8nggnegcwq9nqc'  'negative'
'vk4ga34492m01hwv'  'negative'
'vk4ga34492m01hwv'  'negative'
'vk4ga34492m01hwv'  'negative'
'vk4ga34492m01hwv'  'negative'
'd9hk2zeexhxp2h0v'  'negative'
'f93xk5sq60ehp34j'  'negative'
'f93xk5sq60ehp34j'  'negative'
'ypzzn212hqvwjtc9'  'negative'
'0q2mmnq0wb97z7bm'  'negative'
'jh8k1dd9g2p2d218'  'negative'
'2e5tr0scw89z68kg'  'negative'
'2e5tr0scw89z68kg'  'negative'
'5zb72reqnsxnzuca'  'negative'
'5zb72reqnsxnzuca'  'negative'
'5zb72reqnsxnzuca'  'negative' };

c = categorical(data(:, 1));
[categories(c), num2cell(countcats(c))]

输出如下:

'0q2mmnq0wb97z7bm'  1
'2e5tr0scw89z68kg'  2
'5zb72reqnsxnzuca'  3
'6vmhbj7041fe7xck'  4
'brjmfpunj00rn92c'  2
'd9hk2zeexhxp2h0v'  1
'eddbdv5bsqggeydq'  6
'ekvpmhqybu920hnr'  1
'f93xk5sq60ehp34j'  2
'j5d6dgzbeynyyg02'  3
'jh8k1dd9g2p2d218'  1
'mb8nggnegcwq9nqc'  1
'v21tstcp164uya6g'  2
'vajbfch07wu11y90'  1
'vk4ga34492m01hwv'  4
'ypzzn212hqvwjtc9'  1

我想生成此输出的条形图,显示有多少ID的计数至少为1,有多少ID的计数至少为2,有多少ID的计数至少为3...
我该怎么做呢?
现在我的条形图看起来像这样这不是我想要的

barh(countcats(c)); set(gca, 'YTickLabels', categories(c))

dxpyg8gm

dxpyg8gm1#

有两件事与本案有关yticksyticklabels。为了显示16个yticklabels,您需要在使用yticklabels之前定义16个xticks

barh(countcats(c));
yticks(1:numel(countcats(c)));
yticklabels(categories(c));

相关问题