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)
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!