MATLAB: How to make both yyaxis axes zoom together

callbackMATLABplotyyyyaxiszoom

When I plot two figures using "yyaxis" and use the interactive zoom, only the right (active) axis zooms. The other one does not get updated. How can I fix this?

Best Answer

This behavior is in accordance with the "yyaxis" function documentation (See under "Axes Properties" in the "More About" section of the link below)
However, you can achieve the desired behavior by following these steps:
1. Plot your data using "yyaxis" as normal
2. Create a callback function that, before the zoom happens, saves the old axis limits.
3. Create a callback function that, after the zoom happens, edits the axis values for the (previously unaffected) left axis.
In the attached files, file saveAxisStatus.m defines the pre-zoom callback behavior, and zoomSecondAxis.m defines the post-zoom callback behavior. The file Example.m demonstrates how to use these two functions.