フィルターのクリア

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 Center および File ExchangeTwo y-axis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by