MATLAB Answers

plotyy is not working properly???

6 ビュー (過去 30 日間)
Chris E.
Chris E. 2013 年 10 月 28 日
コメント済み: Chris E. 2014 年 2 月 3 日
Well I have an application for "plotyy" function, So I find if I ever zoom in anywhere on the plot, one of the axis stick in a zoomed position when you click on "reset to original view". One axis resets but the other does not. I did no modifications to "plotyy" function, so I was wondering if someone out there knows how to fix this issue with "plotyy" or if someone knows why it is doing this. If someone needs code to work with, here is an example:
figure
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
plotyy(x,y1,x,y2,'plot');
To see the problem, simply zoom in and then zoom out or reset with the right click of the mouse! Thanks!

採用された回答

David Sanchez
David Sanchez 2013 年 10 月 28 日
Your code is right, I run it and it works for me with no problem. Besides, it is from matlab documentation, for which it should work properly. I think your problem lies on your machine/system.
  1 件のコメント
Chris E.
Chris E. 2013 年 10 月 28 日
Well I am running on linux machine... I wonder if it is my OS or my machine... Thanks anyway....

サインインしてコメントする。

その他の回答 (2 件)

Bernard
Bernard 2014 年 1 月 31 日
I am on a Windows machine and it does the same thing for me.
Furthermore, if you were to plot several objects on each of the two axes, when you zoom in, it will not affect any of the line objects except the one that was plotted last. I cannot zoom in on the solid green line.
figure(1)
hold on
x = 0:0.01:20;
yL{1} = 1*sin(x);
yL{2} = 2*sin(x);
yR{1} = -5*sin(x);
yR{2} = -6*sin(x);
LS = {'-', '-.'}; %Line Style
for f = 1:2 %Two data files plotted on the same Y-Y plot
[ax, hL, hR] = plotyy(x,yL{f},x,yR{f});
set(ax(1),...
'XLim', [0 5],...
'YLim', [-2 2])
set(ax(2),...
'XLim', [0 5],...
'YLim', [-7 7],...
'XTick', [])
set(hL, 'LineStyle', LS{f})
set(hR, 'LineStyle', LS{f})
end

Bernard
Bernard 2014 年 2 月 3 日
I have found the solution:
fh = figure;
for f = 1:n
[AX(:, f), H1(f), H2(f)] = plotyy(x1{f}, y1{f}, x2{f}, y2{f}); %Plot several traces on the same YY-plot.
OldYLim1(f,:) = get(AX(1, f), 'YLim'); %Store the old YLim's for future reference
OldYLim2(f,:) = get(AX(2, f), 'YLim');
end
hZoom = zoom(fh); %Get the zoom mode object handle
hPan = pan(fh); %Get the pan mode object handle
handles.ax = AX; %Store the axis handles in a structure (so that a single variable can be passed to the function)
handles.OldYLim1 = OldYLim1; %Store the old y limits in the handles structure for the same reason
handles.OldYLim2 = OldYLim2;
set(hZoom, 'ActionPostCallback', {@zoomyy, handles}); %Set the Action Post Callback function for the Zoom and Pan features to a user-created function
set(hPan, 'ActionPostCallback', {@zoomyy, handles});
function zoomyy(fig,evd,handles) %#ok<INUSL>
ax = handles.ax;
OldYLim1 = handles.OldYLim1;
OldYLim2 = handles.OldYLim2;
for f = 1:length(ax(2,:))
NewXLim1 = get(ax(1,f),'XLim');
NewYLim1 = get(ax(1,f),'YLim');
YFactor = OldYLim2(f,:)./OldYLim1(f,:);
NewXLim2 = NewXLim1;
NewYLim2 = NewYLim1.*YFactor;
set(ax(2,f), 'XLim', NewXLim2);
set(ax(2,f), 'YLim', NewYLim2);
end
  1 件のコメント
Chris E.
Chris E. 2014 年 2 月 3 日
Thank you! Its been a while since I have needed that, but I will look through it and update it. Thanks!

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by