Azzera filtri
Azzera filtri

plotyy xaxis not aligned with 'keeptick' and datenum

2 visualizzazioni (ultimi 30 giorni)
nori
nori il 27 Apr 2012
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)

Risposte (1)

Thomas
Thomas il 27 Apr 2012
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 Commenti
nori
nori il 27 Apr 2012
edit: I just looked a bit closer and the solution seems to change the month order
Thomas
Thomas il 27 Apr 2012
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..

Accedi per commentare.

Categorie

Scopri di più su Two y-axis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by