how to plot the time series data with dates showing in x axis
显示 更早的评论
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.
采纳的回答
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 个评论
Dear Cris, tnx
it should be ....,'excel')
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?
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')
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.
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.
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.
Dear Cris, I attached P(pressure) and T(temperature). I really appreciate your help. Thanks.
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.
Dear Cris, I really appreciate. I could fixed it
figure
pcolor(datenum(Time),-P,S);shading flat;colorbar
datetick('x', 'yyyy-mmm', 'keepticks')
(thanks)^10000000
Very good! Glad you got it working.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Time Series Objects 的更多信息
标签
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
