Need to line up two graphs on same plot

I am using
[AX,H1,H2] = plotyy(time,Y1,time,Y2);
The x-axis(time) are the same for both. The green and blue graphs in the image both end at the same point, but notice how the green graph starts earlier. I want to line both graphs up so that they have the same starting and ending points. For some of the other graphs I've made, it's done by default. I'm not sure what is different with this set of data...
Any help is appreciated. Thanks! :)

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 11일

0 개 추천

Maybe your data contains Nan values?

댓글 수: 6

Benson
Benson 2013년 7월 11일
I checked my data and there are no Nan values.
I think the problem is that the plot is using two separate x-axes. If you look closely at the image, there are some additional ticks that shouldn't be there. They are unlabeled because I have set(AX, 'xTickLabel','') in my code. Not sure why it's happening...
Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 11일
post your code
Benson
Benson 2013년 7월 11일
편집: Benson 2013년 7월 11일
figure;
set(0,'DefaultLineMarkerSize',6);
[AX,H1,H2] = plotyy(time,y1,time,y2);
title(['title']);
xlabel('Time (UTC)');
set(AX, 'xTickLabel','')
set(gca,'XTickLabel',{'00:00','01:00','02:00','03:00','04:00'...
'05:00','06:00','07:00','08:00','09:00','10:00','11:00'...
'12:00','13:00','14:00','15:00','16:00','17:00','18:00'...
'19:00','20:00','21:00','22:00','23:00','24:00'});
set(get(AX(1),'Ylabel'),'String','axistitle','Color','black');
set(get(AX(2),'Ylabel'),'String','axistitle','Color','black')
set(AX(1),'ycolor','black')
set(AX(2),'ycolor','black')
set(AX(1),'box','off')
set(H1,'Marker','.')
set(H2,'Marker','.')
legend('legend1', 'legend2')
axis([13 21-Inf Inf]);
Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 11일
편집: Azzi Abdelmalek 2013년 7월 11일
If you just write
close
[AX,H1,H2] = plotyy(time,y1,time,y2);
What do you get?
Benson
Benson 2013년 7월 11일
편집: Azzi Abdelmalek 2013년 7월 11일
Interesting, the axes are lined up the way I want it to be.
Benson
Benson 2013년 7월 11일
편집: Benson 2013년 7월 11일
So by trial and error, I found that this line is causing the shift. axis([13 21-Inf Inf]);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by