필터 지우기
필터 지우기

Zooming separately on both data sets while using plotyy

조회 수: 10 (최근 30일)
Donald John
Donald John 2013년 9월 13일
Is there anyway that I can selectively zoom on the two data sets when I am using plotyy?
In other words I want to re-scale and position the the data separately after plotting and can't seem to make this happen as of now. I came across the following but, I wasn't sure how I could convert it into a function for automatic plotting using plotyy:
  댓글 수: 2
dpb
dpb 2013년 9월 13일
You've already got two independent axes w/ plotyy -- the only real piece it would seem you'd need to add would be to hide the non-selected of the two axes when selected the other -- as is by default they both are visible and simply overlay so it visually looks as though there's only one.
Donald John
Donald John 2013년 9월 16일
Thanks for this comment, how would I go about hiding each axis so that I could seperately zoom in that case?
Can I do this in the Figure window with the plot tools, or would I have to write this in the code?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2013년 9월 16일
The sense of PLOTYY is the joining of the data-sets. When you want to handle them separately, do not use PLOTYY, but create the two axes manually:
AxesH(1) = axes('NextPlot', 'add', ...
'XAxisLocation', 'bottom', ...
'YAxisLocation', 'left');
AxesH(2) = axes('NextPlot', 'add', ...
'XAxisLocation', 'top', ...
'YAxisLocation', 'right', ...
'Color', 'none');
plot(1:10, rand(1:10), 'Color', [1,0,0], 'Parent', AxesH(1), ...
'ButtonDownFcn', {@LineSelect, AxesH});
plot(1:10, rand(1:10), 'Color', [0,0,1], 'Parent', AxesH(2), ...
'ButtonDownFcn', {@LineSelect, AxesH});
function LineSelect(ObjectH, EventData, AxesH)
SelectedAxes = get(ObjectH, 'Parent');
Fig = ancestor(SelectedAxesH, 'Figure');
set(Fig, 'CurrentObject', SelectedAxes);
% Now an idea is missing
Finally the code can activate an axes, but I'm not sure if the zooming is restricted to this axes. So this is only a rough idea yet.
  댓글 수: 2
Donald John
Donald John 2013년 9월 16일
편집: Donald John 2013년 9월 16일
Thanks for this. It looks good but zooming does seem to be restricted to the active axis. However the data have a coincident x-axis for which I am using dates. This is the reason I am using plotyy. So all I really want to do is zoom on the separate y-axis, while ensuring that the x-axis remains coincident.
I guess what I need is an option in the figure to select one of the y-axis and zoom on that, then to select the other axis and separately zoom on that axis.
Jan
Jan 2013년 9월 16일
You could link the X-Axes by LINKAXES.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2013년 9월 16일
편집: Sean de Wolski 2013년 9월 16일
You can use the function setAllowedAxesZoom to set false for the axes you don't want zooming. Now, why doesn't this work out of the box? When you call plotyy a bunch of hidden listeners are set up to keep the axes aligned, i.e. when one zooms, the other does too.
These listeners are not initiated when generating code for the figure and then setting axes zoom allowed to false. Here's an example with code and instructions:
hFig = figure;
plotyy(1:10,4:13,2:11,1:10:100);
  • Now click File Menu -> Generate Code
  • Save the file as createfigure.m
The signature should look like this:
createfigure(X1, Y1, X2, Y2);
Change the signature to the following
ax = createfigure(X1, Y1, X2, Y2);
And change the last line of the function to
ax = [axes1 axes2];
Now you are passing back the handles to the axes. Get the zoom handle for the figure and turn it off for the second axes. Here's the full example:
hFig = figure;
ax = createfigure(1:10,4:13,2:11,1:10:100);
h = zoom(hFig);
setAllowAxesZoom(h,ax(2),false);
Enjoy zooming!
  댓글 수: 4
Donald John
Donald John 2013년 9월 16일
Sorry again, but I am using MATLAB R2012b and I can't seem to find the Generate Code option in the file ribbon menu. Am I looking in the wrong place?
Sean de Wolski
Sean de Wolski 2013년 9월 16일
Look in the figure file menu at the top left corner of the figure.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by