Greetings,
I need help with plotting the bar graph from: NAO in Matlab.
I have downloaded the data for the graph from: Data with:
NAO = table2array(readtable(websave('AO.csv','https://www.cpc.ncep.noaa.gov/products/precip/CWlink/daily_ao_index/monthly.ao.index.b50.current.ascii.table'),'ReadVariableNames',false));
I have tried plotting it with:
for i = 1:height(NAO)
for j = 2:13
bar(datetime(NAO(i),j-1,1),NAO(i,j),0.1,'b')
hold on
end
end
The plot then end up looking like 'graph.png'.
The first thing I would like to change is to remove the day from the datetime, but I don't know how to do that, especially in a for loop.
The second thing is the xaxis, why does only the first date show and not more dates?
Third thing is the color, why is it all black when I have set all bars to be blue? I want of course all the negative values to be red and all positive values blue but that's a problem for later.
So if anyone has any tips on how to proceed to plot the bar graph that would be great.
Thanks!

댓글 수: 3

Les Beckham
Les Beckham 2023년 11월 7일
편집: Les Beckham 2023년 11월 7일
I think you have an issue with the indexing, for one thing. Can you explain what the data is and what the columns and rows represent, and what you are trying to plot?
As far as the color is concerned, the bars are so narrow that you only see the EdgeColor (which is black by default), not the FaceColor. So, once you straighten out the indexing, change the bar command to something like
bar(..., 'FaceColor', 'b', 'EdgeColor', 'b')
Then the skinny bars will be blue.
Walter Roberson
Walter Roberson 2023년 11월 7일
In my test, the edge color did not default to black ([0 0 0]) but rather to [33 33 33]/256 which is about [0.1294 0.1294 0.1294]
Les Beckham
Les Beckham 2023년 11월 7일
Interesting. I didn't check, I just assumed it was black because it looks black. [0.1294 0.1294 0.1294] is a pretty dark grey.

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

답변 (2개)

Walter Roberson
Walter Roberson 2023년 11월 7일

0 개 추천

First:
ax = gca;
ax.XRuler.TickLabelFormat = 'mmm uuuu';
would change the format to (for example) "Jan 1960"
Third:
You have lots and lots and lots of bars. They are so thin (to fit them all) that all you can see of them is the outline. The default outline color appears to be [33 33 33]/255
Peter Perkins
Peter Perkins 2023년 11월 10일

0 개 추천

Marcus, it looks to me like what you have is a year-by-month array.
As others have said, those bars are mightily thin. Have you considered plotting lines?
T = readtable(websave('AO.csv','https://www.cpc.ncep.noaa.gov/products/precip/CWlink/daily_ao_index/monthly.ao.index.b50.current.ascii.table'),'ReadVariableNames',false);
T.Properties.VariableNames=["Date","Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"];
T2 = stack(T,2:13,"ConstantVariables",1,NewDataVariableName="X",IndexVariableName="Month");
T2.Date = datetime(T2.Date,repmat((1:12)',74,1),1);
T2.Month = [];
TT = table2timetable(T2);
plot(TT,"Date","X")
That is not exactly what you wanted, but not far. A stemplot seems useful:
stem(TT,"Date","X",Marker=".")
But if bar it must be:
bar(TT.Date,TT.X)

카테고리

도움말 센터File Exchange에서 Networks에 대해 자세히 알아보기

제품

릴리스

R2023a

질문:

2023년 11월 7일

답변:

2023년 11월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by