Question about how to put several values in one histogram

2 ビュー (過去 30 日間)
Lingbai Ren
Lingbai Ren 2021 年 9 月 22 日
コメント済み: Lingbai Ren 2021 年 9 月 24 日
I was writing the code for the rock paper scissors game, the last step is to graph the results (i.e player win times, computer win times, and draw times). The number I got for those three are 3,4,3. The histogram part I did as following:
stats_data = [user_win_time,draw,comp_win_time];
figure
stats_plot = histogram(stats_data);
% And the graph I got is attached
It does not look as expected, can anyone help to improve the histogram? Also informing me how to add legends to histogram as well! I appreciate that!

採用された回答

Chunru
Chunru 2021 年 9 月 22 日
You should not use histogram. You should use bar:
bar([3 4 3])
set(gca, 'XTickLabel', ["Player" "Computer" "Draw"])
  1 件のコメント
Lingbai Ren
Lingbai Ren 2021 年 9 月 24 日
Sorry I just saw that! That works great, thank you!

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

その他の回答 (1 件)

Viranch Patel
Viranch Patel 2021 年 9 月 22 日
You can do something like this.
X = categorical({'user win time','draw','computer win time'});
X = reordercats(X,{'user win time','draw','computer win time'});
Y = [3 4 3];
h = bar(X,Y);
For legends you can refer to this answer as well. Hope it helps.
  1 件のコメント
Lingbai Ren
Lingbai Ren 2021 年 9 月 24 日
Thank you, I think bar is a better choice haha

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

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by