이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Generate bar like the attach
조회 수: 11 (최근 30일)
이전 댓글 표시
Dear friends,
How could I plot bar, for the following data. This graph generated by Excel.
Thank you in advance.

댓글 수: 18
DGM
2021년 4월 15일
Depends what you mean by "different nice color". You can specify any color tuple you want, and there are multiple built-in and countless custom colormaps available.
Adam Danz
2021년 4월 15일
This has been addressed in the forum dozens and dozens of times. Search for methods of changing grouped bar colors and if you have any problems implementing the solution show us what you've got.
DGM
2021년 4월 15일
편집: DGM
2021년 4월 15일
If you're asking how to make it look like the excel plot, this is an approximate example.
a = rand(5, 3); % 5 groups of 3 bars
h = bar(a)
cmap=[68 114 196;
165 165 165;
91 155 213]/255;
h(1).FaceColor=cmap(1,:);
h(2).FaceColor=cmap(2,:);
h(3).FaceColor=cmap(3,:);
h(1).EdgeColor=cmap(1,:);
h(2).EdgeColor=cmap(2,:);
h(3).EdgeColor=cmap(3,:);
set(gca,'ygrid','on','xgrid','off')
legend(h,'thing1','thing2','thing3')

Ameri
2021년 4월 15일
Thank you alot of, there are several issue please
1- x (number of nodes must be 40 60 80 90 100) not from 1 to 5
2- y (pdr ratio) classified as (10 20 30 40 50 60 70 80 90 100)
3- each bar must refers to his data from excel
I am very grateful for your help

DGM
2021년 4월 15일
For clarification:
a = rand(5, 3);
is a placeholder. You're supposed to include your data.
Consider the example:
x = [5 10 15 20];
y1 = [11 12 13 14]; % this is one dataset
y2 = [14 15 16 17]; % this is another dataset
y3 = [17 18 19 20]; % and so on
y = cat(1,y1,y2,y3)'; % concatenate them
h = bar(x,y); % plot them
cmap=[68 114 196;
165 165 165;
91 155 213]/255;
h(1).FaceColor=cmap(1,:);
h(2).FaceColor=cmap(2,:);
h(3).FaceColor=cmap(3,:);
h(1).EdgeColor=cmap(1,:);
h(2).EdgeColor=cmap(2,:);
h(3).EdgeColor=cmap(3,:);
set(gca,'ygrid','on','xgrid','off')
legend(h,'thing1','thing2','thing3','location','northwest')
You can either include those vectors as literals or by reading them in from an excel file.
Ameri
2021년 4월 15일
Many thanks, this is exctly what I want, I have just one qustions more about giving a good layout and what about the number of array you wrote them based on what please . Many thanks in advance.

Ameri
2021년 4월 15일
How could control on the space between the group of cloumns please like space between ( 40 and 60 )please
Ameri
2021년 4월 15일
1- Here a gap or space between some bars is large, where the space between (80 - 90 ) is small, while the space between (40-60) is large. how could make this space are equlals between groups please.
2-and what about this please ? how you selected this number and why
cmap=[68 114 196;
165 165 165;
91 155 213]/255;
DGM
2021년 4월 15일
편집: DGM
2021년 4월 15일
I'm sorry. I didn't see your prior comment. This site tends to be laggy about updating sometimes.
For question 1, that's happening because x has uneven spacing. Try using a categorical array for x:
x = categorical([40 60 80 90 100]);
For question 2, that's a colormap I derived from the image of the excel bar chart you posted. You can use whatever colormap you want. They're just RGB values.
Walter Roberson
2021년 4월 16일
That works.
These days we recommend switching to readtable() instead of xlsread()
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Data Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)


