フィルターのクリア

Plotting bar graph from website

2 ビュー (過去 30 日間)
Marcus Johnson
Marcus Johnson 2023 年 11 月 7 日
回答済み: Peter Perkins 2023 年 11 月 10 日
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 件のコメント
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 日
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 日
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)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by