Plotting bar graph from website

1 回表示 (過去 30 日間)
Marcus Johnson
Marcus Johnson 2023 年 11 月 7 日
回答済み: Peter Perkins 2023 年 11 月 10 日
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',''),'ReadVariableNames',false));
I have tried plotting it with:
for i = 1:height(NAO)
for j = 2:13
hold on
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.
  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 日
ax = gca;
ax.XRuler.TickLabelFormat = 'mmm uuuu';
would change the format to (for example) "Jan 1960"
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',''),'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);
That is not exactly what you wanted, but not far. A stemplot seems useful:
But if bar it must be:


Help Center および File Exchange2-D and 3-D Plots についてさらに検索




Community Treasure Hunt

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

Start Hunting!

Translated by