Question about how to put several values in one histogram
조회 수: 2 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
Chunru
2021년 9월 22일
You should not use histogram. You should use bar:
bar([3 4 3])
set(gca, 'XTickLabel', ["Player" "Computer" "Draw"])
추가 답변 (1개)
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);
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!