plotyy is not working properly???
2 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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.
更多回答(2 个)
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
0 个评论
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!