Set specific date ticks

132次观看(最近30天)
EM
EM 上13 Oct 2017
Hi trying to set specific date ticks. I don't understand why the following code does not work
figure()
hold
盒子
情节(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)

接受的答案

Walter Roberson
Walter Roberson 上13 Oct 2017
DateTick('X', dateF或者mat,'keepticks')
5 Comments
Walter Roberson
Walter Roberson 上21 Oct 2017
您的date1似乎是DateTime对象,您似乎正在使用R2016B或更高版本。在这种情况下,您不使用DateTick。
figure()
hold
盒子
情节(date1,series1,'K')
情节(date1,series2,'r-')
Xlabel('Date')
ylabel('Price')
DateString = {'06/30/2010';'11/30/2010'};
ticlocs = dateTime(datestring);%R2014B或更高版本
ticlocs。格式='dd-MMM-yyyy';
set(GCA,'xtick', ticklocs);%R2016B或更高版本

Sign in to comment.

更多的Answers (2)

彼得·珀金斯
彼得·珀金斯 上13 Oct 2017
编辑:Walter Roberson 上13 Oct 2017
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));
情节(D,X1)
ax = gca;
ax.xaxis.tickvalues = dateTime(2015,1,1)+calquarters(0:6);
ax.xaxis.ticklabelformat ='QQQ-yyyy';
3 Comments
EM
EM 上13 Oct 2017
谢谢沃尔特,这非常有帮助。

Sign in to comment.


Med Aymane Ahajjam
Med Aymane Ahajjam 上14 May 2019
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';

s manbetx 845

社区寻宝

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

开始狩猎!