Plotting bar graph from website
조회 수: 2 (최근 30일)
이전 댓글 표시
Greetings,
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
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
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
2023년 11월 7일
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
댓글 수: 0
Peter Perkins
2023년 11월 10일
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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Bar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!