フィルターのクリア

Add dates in x-axis

35 ビュー (過去 30 日間)
kounoupaki87
kounoupaki87 2020 年 5 月 24 日
コメント済み: kounoupaki87 2020 年 5 月 24 日
Hi, I have data for 3months (Jan-Mar). I want to plot them and have the date in x-axis:
cgf=figure;
Days=(1:90);
plot(Days,df,'b.-');
grid on;axis tight;
%x-axis
xticks([1:1:Days]);
datetick('x','dd','keepticks');
but it is not working:/

採用された回答

Gautam
Gautam 2020 年 5 月 24 日
Referring the doc: datetick is useful when plotting numeric values that are serial date numbers. Days is just an array of numbers and not actually serial date numbers. Instead, use datetime to create your dates info and then plot.
d1 = datetime('01/01/2020','InputFormat','dd/MM/uuuu');
d2 = datetime('30/03/2020','InputFormat','dd/MM/uuuu');
days = d1:1:d2; % Creates your x-axis, 90 dates from Jan 1st to March 30
figure(1)
plot(days,df,'b.-')
grid on, axis tight
datetick('x','dd/mmm'); %datetick('x','dd') will show 90 x-axis ticks, which may not look neat in the plot
  1 件のコメント
kounoupaki87
kounoupaki87 2020 年 5 月 24 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by