フィルターのクリア

Bar plot error when plotting

1 回表示 (過去 30 日間)
chiefjia
chiefjia 2021 年 9 月 25 日
コメント済み: Ive J 2021 年 9 月 26 日
Dear MATLAB experts,
I'm trying to create a bar plot with the column 'position_holder' in the x axis and the column 'percentage' in the y axis.
I want to only plot the first 20 rows of this two columns, but even if I explicitly create a new table with these 20 rows, MATLAB keeps on plotting all rows included in the position_holderFrequency table, when it should just be including the 20 rows from position_holderFrequencyHead.
Therefore, the plot created is all over the place and not useful at all (see attachment). I don't know if this is a problem from MATLAB itself or there is something wrong in the code written, but I would really be thankful for your guidance.
Thank you in advance.
% Plot the histogram for column 'position_holder'
figure('Name', 'Frequency of Appearance of position_holder', 'NumberTitle', 'off');
position_holderFrequency.position_holder = categorical(position_holderFrequency.position_holder);
% Need to create a new table because bar is not able to process only the
% first 20 rows
position_holderFrequencyHead = position_holderFrequency(1:20, [1 3]);
bar(position_holderFrequencyHead.position_holder, position_holderFrequencyHead.percentage);
xlabel('position_holder')
ylabel('%')
title('Distribution of position_holder Frequency')
  2 件のコメント
Ive J
Ive J 2021 年 9 月 26 日
Can you upload your dataset? Your snipped needs position_holderFrequency to run.
chiefjia
chiefjia 2021 年 9 月 26 日
done

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

採用された回答

Ive J
Ive J 2021 年 9 月 26 日
編集済み: Ive J 2021 年 9 月 26 日
The main problem is that your tick labels are too long to fit under the axes. You can try something like this:
figure('Name', 'Frequency of Appearance of position_holder', 'NumberTitle', 'off');
% data = position_holderFrequency(1:20, [1 3]);
data = table(["Marshall Wace LLP";"BlackRock Investment Management (UK) Limited";"AQR Capital Management, LLC";"Citadel Europe LLP";"BlackRock Institutional Trust Company, National Association";"WorldQuant, LLC";"MARSHALL WACE LLP";"Millennium International Management LP";"JPMorgan Asset Management (UK) Ltd";"GLG Partners LP";"GSA Capital Partners LLP";"Citadel Advisors LLC";"WorldQuant LLC";"AKO Capital LLP for AKO Master Fund Limited";"Adage Capital Management L.P.";"Capital Fund Management SA";"Oxford Asset Management";"AHL Partners LLP";"ODEY ASSET MANAGEMENT LLP";"TT International"], [12.4109;4.87476;4.17665;2.50779;2.35796;2.16306;2.14916;2.05453;2.02674;1.88817;1.71693;1.35153;1.19794;1.05712;1.0267;0.989898;0.979383;0.959856;0.953096;0.823538], 'VariableNames', {'position_holder', 'percentage'});
h = bar(data.percentage);
h.Parent.XTick = 1:size(data, 1);
h.Parent.XTickLabel = data.position_holder;
h.Parent.XTickLabelRotation = 35; % rotate labels
h.Parent.XAxis.FontSize = 7; % reduce font size fo better visualization
You may want to also use some acronyms in this case.
  4 件のコメント
chiefjia
chiefjia 2021 年 9 月 26 日
Perfect, thanks again!
Ive J
Ive J 2021 年 9 月 26 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by