Xtick location is not correct

4 views (last 30 days)
MINA on 1 Jun 2016
Commented: dpb on 2 Jun 2016
I have two plots on one figure, which is shown in the attachment. The X tick for both of the the plots should be in the same location but they are not. Could someone please help me how I can fix this problem.
dpb on 2 Jun 2016
ax1 = gca; % be better to
ax(1)=axes; % create axes/save handle instead of gca
ylabel(ax(1),'Trials #','fontsize',10);
xlabel(ax(1),'Time (s)','fontsize',10);
ylabel(ax(2),'Average Speed (cm/s)','fontsize',10);
What you're missing above is setting xlim to match the 'xtick' and then linking the two x-axes
linkaxes(ax,'x') % link the two x-axes to keep in synch
xlim(ax(2),[0 16]) % now set the limits to match where tried put ticks
Also notice used array to hold the handles instead of named variables--this way when need both can use the array name instead of building vector (in, say linkaxes)

Sign in to comment.

Answers (1)

dpb on 1 Jun 2016
You'll have to set the two axes xlim ranges to a consistent set of ticks and range. It's difficult to interpret but I guess both axes are actually time and the Speed is supposed to be a Title, not an axis label? If that is so, look at
doc linkaxes % to connect the two so they stay in synch irregardless of what do to one or t'other.
It's always easier to give more precise information when the code that generated the figure is shown; often experienced users here can spot "issues" causing such problems that aren't so apparent to the neophyte (else't they wouldn't have to be asking now, would they? :) )
  1 Comment
MINA on 1 Jun 2016
That's right. Both of axes are time and the Speed is the title.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!