how to plot the time series data with dates showing in x axis
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
I can plot time series but I am not able to show exact dates on x axis. I really appreciate anybody can help me. Thanks
figure
Ts = timeseries(Ta);
plot(Ts,'r')
grid on
grid minor
xlabel('Time','fontsize',14)
ylabel('Temperature (\circC)','fontsize',14)
Problem, cannot manage date lable, you can find attached file may show me how it's work.
Accepted Answer
Cris LaPierre
on 18 Mar 2020
Edited: Cris LaPierre
on 18 Mar 2020
Convert your dates to the datetime data type. Then, when you plot using the datetime, the date will appear on the axis. You can set the display format of a datetime to show the date however you'd like.
load example.mat
Time = datetime(time,'ConvertFrom',"excel")
plot(Time,Ta)
14 Comments
Farshid Daryabor
on 18 Mar 2020
Dear Cris, tnx
it should be ....,'excel')
Farshid Daryabor
on 19 Mar 2020
Dear Cris,
Years has been displayed form of 0066-May, 0066-Jun,0067-Jan,...etc. I would to be 2016-May, 2016-Jun, ...etc. Year reference is 1950. You know how can I do it?
Cris LaPierre
on 19 Mar 2020
Edited: Cris LaPierre
on 19 Mar 2020
Interesting. The code I shared imports the year as 1966, 1967, etc for me.
For me, your vector time appears to be in units of days. So if the reference data is 01-01-1950, the first date is around 12-06-2016. Does that sound correct?
If your time does not correspond to a built-in option, you can specity your own epoch. However, this appears to expect the time values to be in seconds, not days. You can modify the datetime conversion to the following to account for this:
% Convert time from days to seconds for conversion. Reference is 1950
Time = datetime(time*60*60*24,'ConvertFrom','epochtime','Epoch','1950-01-01')
Farshid Daryabor
on 19 Mar 2020
Dear Cris,
I really appreciate your patience, Time reference is "1950-01-01T00:00:00Z". I want to be in format "mmm-yyyy", and also "dd-mmm-yyyy" , thanks.
Cris LaPierre
on 19 Mar 2020
Farshid Daryabor
on 19 Mar 2020
Dear Cris, I fixed the date, proble is plotting. Could you tell me how can I fixed it. Thanks
>> pcolor(Time,-P,T);shading flat;colorbar; colormap(jet)
Error using pcolor (line 63)
Data inputs must be real.
Cris LaPierre
on 19 Mar 2020
Edited: Cris LaPierre
on 19 Mar 2020
I don't know what P and T are, so I can't reproduce your error. Perhaps this post can help with the error you are seeing? Especially if you are using MATLAB r2019a or older.
Farshid Daryabor
on 19 Mar 2020
Dear Cris, I attached P(pressure) and T(temperature). I really appreciate your help. Thanks.
Cris LaPierre
on 19 Mar 2020
And what version of MATLAB are you using? If 2019a or earlier, look at the two posts I've already shared that show you how to fix this.
Farshid Daryabor
on 19 Mar 2020
Matlab2016
Cris LaPierre
on 19 Mar 2020
Farshid Daryabor
on 19 Mar 2020
Dear Cris, I really appreciate. I could fixed it
figure
pcolor(datenum(Time),-P,S);shading flat;colorbar
datetick('x', 'yyyy-mmm', 'keepticks')
Farshid Daryabor
on 19 Mar 2020
(thanks)^10000000
Cris LaPierre
on 19 Mar 2020
Very good! Glad you got it working.
More Answers (0)
Categories
Find more on Time Series Objects in Help Center and File Exchange
Tags
See Also
on 18 Mar 2020
on 19 Mar 2020
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)