Plotting monthly precipitation and time
이전 댓글 표시
Hello There, Essentially I'm trying to plot x (time) and y (precipitation). x = [7/15/05 8/9/05 9/15/05 10/16/05 11/17/05 12/28/05 3/8/06 4/12/06 5/13/06 6/17/06 7/16/06 8/9/06 9/10/06 10/9/06 11/4/06 11/29/06 1/2/07];
y = [2.9 0.51 21.49 25.76 13.16 8.46 11.1 3.38 4.85 14.20 3.05 1.45 19.290 0.20 1.17 0.00 7.67];
The code i'm using is: figure(1) plot(x,y);grid;datetick('x','mm/dd/yyyy')
However my x axis is not plotting on the correct scale (attached figure). I seem to be missing a step. Any suggestions would be helpful! Cheers,
댓글 수: 1
Von Duesenberg
2017년 1월 9일
Hi. Perhaps you could post your code exactly as you typed it in Matlab (I copied and pasted your example but wasn't able to replicate your figure).
채택된 답변
추가 답변 (1개)
Ed Marquez
2017년 1월 11일
Hi, I am assuming you are using MATLAB R2014b or later. My understanding is that you would like to plot the values contained in 'y' (precipitation data) versus the values contained in x, which are dates.
First you will need to redefine your 'x' vector to be a cell array containing characters, as shown below:
x = {'7/15/05';'8/9/05';'9/15/05';'10/16/05';'11/17/05';'12/28/05';'3/8/06';'4/12/06';'5/13/06';...
'6/17/06';'7/16/06';'8/9/06';'9/10/06';'10/9/06';'11/4/06';'11/29/06';'1/2/07'};
The 'y' vector you are using can stay as is.
After that you can try the code below:
a = datenum(x);
b = datestr(x,'mmm-dd-yyyy');
figure(1)
axObj = axes;
plot(a,y);
grid;
datetick('x','mm/dd/yyyy')
axObj.XTick = (a);
axObj.XTickLabels = (b);
axObj.XTickLabelRotation = 45;
댓글 수: 1
Peter Perkins
2017년 1월 12일
Just in case it wasn't clear from Ed's post, x in the OP's code is very different than intended:
>> x = [7/15/05 8/9/05]
x =
0.093333 0.17778
Without enclosing quotes, those slashes are divisions.
카테고리
도움말 센터 및 File Exchange에서 Weather and Atmospheric Science에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!