Inconsistent xlim when using yyplot (matlab 2014a)
显示 更早的评论
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 个评论
dpb
2016-12-9
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]);
...
[ax2,hlines1,hlines2] = plotyy(dist,abs(Z4_ATS1_f3(L1:L2)),dist,Z4_ATS1_f3ang(L1:L2));
You're writing over the axes handle you previously created; this can't be good. Can't test here, but I'd guess this is a major problem in that you're no longer actually operating on the axes you think you are with that handle...
Nick Burnham
2016-12-12
dpb
2016-12-12
Don't know what your end object really is, but if the point is to have two axes of the positions shown first, then use those axes in calls to plot, line and friends (with hold state set appropriately for first, subsequent calls). If the effect of plotyy is intended, then set 'YAxisLocation','right' for ax2.
Or, while I've never tried it, guess one could ditch the two axes calls in lieu of one plotyy (change ax2 to hAx or some similar generic array name for axes handles) and then set the 'position' property for hAx(2) if don't want the two to overlap.
Nick Burnham
2016-12-12
dpb
2016-12-12
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...
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Two y-axis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!