Plotting monthly precipitation and time
Mostrar comentarios más antiguos
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 comentario
Von Duesenberg
el 9 de En. de 2017
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).
Respuesta aceptada
Más respuestas (1)
Ed Marquez
el 11 de En. de 2017
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 comentario
Peter Perkins
el 12 de En. de 2017
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.
Categorías
Más información sobre Weather and Atmospheric Science en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!