plotyy xaxis not aligned with 'keeptick' and datenum

2 次查看(过去 30 天)
good afternoon matlabers! so i have been trying to plot 2 datasets with different y-axis using plotyy and to have the date displayed on the x-axis. when i plot the data using the below code, the x-axis is not aligned.
but if i remove the datetick and just use time = linspace(1,12,12); everything works fine.
any suggestions?
y1 = rand(12,1);
y2 = rand(12,1);
startDate = datenum('01-01-2010');
endDate = datenum('12-31-2010');
time = linspace(startDate,endDate,12);
% time = linspace(1,12,12);
figure
hold on
set(gca,'XTick',time, 'XMinorTick', 'on','XGrid','on')
datetick('x','yyyy/mmm','keepticks')
plotyy (time,y1,time,y2)

回答(1 个)

Thomas
Thomas 2012-4-27
Clear the XTickLabel before using datetick.. remove hold.. That should solve the problem..
y1 = rand(12,1);
y2 = rand(12,1);
startDate = datenum('01-01-2010');
endDate = datenum('12-31-2010');
time = linspace(startDate,endDate,12);
% time = linspace(1,12,12);
figure
% hold on
set(gca,'XTick',time, 'XMinorTick', 'on','XGrid','on')
[AX,H1,H2]=plotyy (time,y1,time,y2)
set(AX,'XTickLabel',[])
datetick('x','yyyy/mmm','keepticks')
EDIT This takes care of the ticks coming out wrong..
y1 = rand(12,1);
y2 = rand(12,1);
startDate = datenum('01-01-2010');
endDate = datenum('12-31-2010');
time = linspace(startDate,endDate,12);
% time = linspace(1,12,12);
figure
%hold on
[AX,H1,H2]=plotyy (time,y1,time,y2)
set(AX,'Xtick',[],'XTickLabel',[],'Xlim',[min(time) max(time)])
set(gca,'Xtick',time,'XGrid','on')
datetick('x','mmm','keepticks')
  3 个评论
nori
nori 2012-4-27
edit: I just looked a bit closer and the solution seems to change the month order
Thomas
Thomas 2012-4-27
The Xticks were plotting in the middle of the months giving unaligned ticks with the date tick which was always the 1st of the month..

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Two y-axis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by