Inconsistent xlim when using yyplot (matlab 2014a)

2 views (last 30 days)
Hi,
I am trying to plot two y axis onto one x axis using yyplot.
This has worked but i sometimes get inconsistent x limits. I have tried using xlim to correct:
xlim(ax2(1), [1 6]);
xlim(ax2(2), [1 6]);
But this makes both plots disappear! Can anyone tell me what i'm doing wrong? My Code is copied below:
fig = figure('Name','Z4_ATS1_f3 Plot','NumberTitle','off');
ax1 = axes('Position',[0 0 1 1],'Visible','off');
ax2 = axes('Position',[.3 .1 .6 .8]);
xlabel('Distance [meters]');
ylabel('Impedance (absolute)');
descr = {'Impedance Values';
' '
'Towards SATS: ';
'@ 50% distance:'
num2str(Z4_ATS1_f4_toSATS_50);
'With 15% added:';
num2str(Z4_ATS1_f4_toSATS_50_wTol);
' '
'Towards FS: ';
'@ 50% distance:'
num2str(Z4_ATS1_f4_toFS_50);
'With 15% added:';
num2str(Z4_ATS1_f4_toFS_50_wTol)};
axes(ax1) % sets ax1 to current axes
text(.025,0.6,descr);
axes(ax2) % sets to ax2 enables zooming of the graph not the text
[ax2,hlines1,hlines2] = plotyy(dist,abs(Z4_ATS1_f3(L1:L2)),dist,Z4_ATS1_f3ang(L1:L2));
% xlim(ax2(1), [1 6]);
% xlim(ax2(2), [1 6]);
% set(ax2(1),'xtick',0:1:6);
% set(ax2(1),'xlim',[0 6]);
% set(ax2(2),'xtick',0:1:6);
% set(ax2(2),'xlim',[0 6]);
set(ax2(1),'ytick',0:2:20);
set(ax2(1),'ylim',[0 20]);
ylabel(ax2(1),'Impedance (absolute)');
set(ax2(2),'ytick',-180:36:180);
set(ax2(2),'ylim',[-180 180]);
ylabel(ax2(2),'Angle (deg)');
saveas(gcf,['Z4_ATS1_f3.fig']);
  5 Comments
Nick Burnham
Nick Burnham on 12 Dec 2016
My goal is to have a figure with two Y axes plot against the same x axes with a description somewhere on the figure.
So if there is an easier way to accomplish that than what I'm trying to do, then please let me know.
In the meantime I'll have a play with positioning inside plotyy.
Cheers again Nick
dpb
dpb on 12 Dec 2016
What's wrong with just straight plotyy, then as illustrated in the doc if you're still with earlier release or yyaxis in conjunction with standard plot and friends if have HG2 for which plotyy has been deprecated (altho for oldtimers used to working with HG handles directly, it doesn't seem that much benefit to have more "stuff" to do same thing in end, eventually it'll probably come out about the same as far as effort as TMW continues to streamline HG2).
Plot the lines on the two axes as desired, set their y-,xlabels appropriately and add a figure title or use text...

Sign in to comment.

Answers (0)

Categories

Find more on Two y-axis in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!