필터 지우기
필터 지우기

plotyy xaxis not aligned with 'keeptick' and datenum

조회 수: 2 (최근 30일)
nori
nori 2012년 4월 27일
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