필터 지우기
필터 지우기

Creating a stacked bar plot

조회 수: 293 (최근 30일)
Sophie Stringer
Sophie Stringer 2019년 9월 7일
댓글: Stephen23 2019년 9월 8일
Hi there,
I have a a matrix of percentages (P):
11.8227 13.4058 11.8959 13.2316 15.0877 7.6389 17.0667 17.8899 14.1361
12.0690 11.5942 14.1264 14.7583 12.9825 17.3611 14.6667 11.9266 15.1832
8.3744 9.7826 12.6394 7.3791 9.8246 19.4444 10.4000 11.4679 7.8534
9.8522 10.5072 13.7546 12.9771 10.8772 17.3611 12.0000 14.2202 16.7539
14.7783 15.5797 14.4981 13.9949 12.2807 11.1111 14.1333 13.3028 12.5654
14.7783 14.4928 14.1264 12.4682 14.0351 12.5000 11.4667 10.0917 12.0419
13.5468 9.7826 12.2677 12.4682 9.8246 5.5556 9.6000 9.6330 12.5654
14.7783 14.8551 6.6914 12.7226 15.0877 9.0278 10.6667 11.4679 8.9005
Where each column (vertically) above adds to 100 and each column is a particular node ranging from 1-9. Each row represents phases 1-8 (horizontally).
I would like to make a stacked bar chart for this data. I've done the basic code for a stacked bar plot. And have gotten the graph below. But the axis are the wrong way around. I need the x axis to be columns 1 to 9. And the stacked variables to be the vertical columns (adding to 100). Is there an easy way of doing this?
I have attached the percentage file.
Thank you in advance. :D
figure(15)
bar(P, 'stacked')
Screen Shot 2019-09-07 at 5.12.37 pm.png

채택된 답변

Stephen23
Stephen23 2019년 9월 7일
편집: Stephen23 2019년 9월 7일
The bar documentation states "If y is a matrix, then bar groups the bars according to the rows in y", so you need to translate your matrix:
bar(P.','stacked')
% ^^ translate
untitled.png
  댓글 수: 2
Stephen23
Stephen23 2019년 9월 8일
Sophie Stringer's incorrectly accepted "Answer" moved here:
Thank you, that works!
Cheers,
Sophie :D
Stephen23
Stephen23 2019년 9월 8일
@Sophie Stringer: glad it helped. Please don't forget to accept my answer!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by