Set specific date ticks
古いコメントを表示
Hi trying to set specific date ticks. I don't understand why the following code does not work
figure()
hold on
box on
plot(date1,series1,'k')
plot(date1,series2,'r--')
xlabel('Date')
ylabel('Price')
DateString = {'06/30/2010';'11/30/2010'};
datenum(DateString);
set(gca, 'XTick', datenum(DateString))
dateFormat = 1;
datetick('x', dateFormat)
採用された回答
その他の回答 (2 件)
Peter Perkins
2017 年 10 月 13 日
編集済み: Walter Roberson
2017 年 10 月 13 日
If you have access to R2016b or later, you will probably be much happier using datetime rather than datenum/datestr, including for plotting:
d = datetime(2015,1,1:500);
x1 = randn(size(d));
plot(d,x1)
ax = gca;
ax.XAxis.TickValues = datetime(2015,1,1)+calquarters(0:6);
ax.XAxis.TickLabelFormat = 'QQQ-yyyy';

3 件のコメント
EM
2017 年 10 月 13 日
Walter Roberson
2017 年 10 月 13 日
Yup. For example,
ax.XAxis.TickValues = datetime(2015,1,1)+days([18 143 207 258]);
ax.XAxis.TickLabelFormat = 'MMM dd';
or
ax.XAxis.TickValues = datetime(2015,[1;5;11;14], [17;5;30;19]);
ax.XAxis.TickLabelFormat = 'yy/M/d';
EM
2017 年 10 月 13 日
Med Aymane Ahajjam
2019 年 5 月 14 日
0 投票
In order for the TickLabelFormat to work, at least in my case, I had to specify:
ax.XTickLabelMode = 'manual';
ax.XAxis.TickLabelFormat = 'HH:mm:ss';
カテゴリ
ヘルプ センター および File Exchange で Grid Lines, Tick Values, and Labels についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!