Set specific date ticks
132次观看(最近30天)
节目older comments
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)
0 Comments
接受的答案
Walter Roberson
上13 Oct 2017
DateTick('X', dateF或者mat,'keepticks')
5 Comments
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或更高版本
更多的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';
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';