How can I plot these two variable in bars?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have these two variables one of values of each month(C) and the other with the names of the corresponding values(T) I mean the names under the bars of each value of VARIABLE C. How can I plot them where we could see each other well? I attached the file with the variables. Than you in advance
채택된 답변
load sl % get variable titles
T=categorical(T); % turn into categorical variable
C=randi(200,1,numel(T)); % make up some data to got with...
bar(T,C)
댓글 수: 10
That works!! Could I ask for two things more? how could I chane the color or the bars that are in position 2,4,6? And how could I place the value of the columns up of them? Thank you!
See the examples @ doc bar -- there's one for both of those plus other features as well...
Yeah I already wrote the number up the bar but I could manage to change the color
So, show the code you used -- should be able to mimic the example; we can't know what went wrong if we can't see what you tried.
b = bar(T,C,'FaceColor','flat')
for k = 1:size(C,2)
b(k).CData = k;
end
text(1:length(C),C,num2str(C'),'vert','bottom','horiz','center');
xlabel('Nombre missatges'); ylabel('Mesos')
title('Mitja de missatges de cada mes')
box off
That doesn't mimic the example -- as the doc says, when use CData, it must be a valid RGB triplet; you placed a single integer value.
You also tried to access b(k) for multiple bar handles; there's only one bar oject here. That also is NOT the syntax used in the example that changes the CData array values instead.
Try something like
hAx=gca; % retrieve the current axes handle
for k = 1:size(C,2)
b.CData(k) = hAx.ColorOrder(k,:); % set to default line color triplet in order
end
NB; Above only works as long as number of bars <= the size of the default line color array -- which is eight elements long unless user has modified factory defaults. When/if your number of bars exceeds that, you'll have to build/use a more lengthy colormap array or recycle the default colors.
I'll grant it's arcane and way more trouble than should be; I've railed to TMW about the bar interface for nearly 30 years now. It's only been in last couple they finally(!!!) did something about the bar labels; it's still way too complex to do such simple things as this and dreadfully difficult to do anything not in the pre-canned facilities. As noted to them many times, Excel has, unfortunately, passed them by in this area by lightyears in appearance and abilities. MATLAB bar graphs definitely show their age and need a total revamping. Unfortunately, TMW is hampered by the need for backward compatibility here and is stuck with a ill-guided initial design. $0.02, imo, ymmv, etc., etc., etc., ...
wow I did not know that. Thank you I will try to do it in Excel lets see if I get different colors
By default, certainly. You can set any color your monitor/graphics card can generate so it isn't that it can't be done, only that what one gets by default is not necessarily all that attractive.
I still wouldn't use Excel over MATLAB for much of anything by choice; it's just too klunky in all the other ways in which it handles data, but certainly default graphics now are generally more appearance-friendly than the default in MATLAB.
yeah but its no so much data just 6 numbers
For MATLAB, investigate colormap to learn about more and different choices and how to set/change them.
While inherently utterly flexible, the UI is, unfortunately, still based on 60s-70s era engineer-like syntax of writing code and delving into the internals of "how things work" in order to make changes. "User-friendly" and "rapid development" haven't much evolved into this arena yet if one isn't satisfied with the default colormaps supplied.
You can fiddle with Excel and see how like the color choices, then move those over to MATLAB -- what's newish and different in Excel is all the addtional visual enhancements of how can display that MATLAB just doesn't have equivalents for. Most, if not all, of these probably have more use in business graphics than scientific, but they do tend to have a more modern look and feel about them.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Bar Plots에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
