![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/340855/image.gif)
Linking x and y axis zoom in subplot
조회 수: 163 (최근 30일)
이전 댓글 표시
Hi I am trying to link the x and y axis of these subplots together for when the user uses the mouse wheel to scroll i would like both to be zoomed in. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/340843/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/340843/image.png)
댓글 수: 0
답변 (1개)
Adam Danz
2020년 8월 3일
편집: Adam Danz
2020년 8월 4일
Link the xlim and ylim properties.
Or use or linkaxes()
Here's a demo. It uses tiledlayout instead of subplot but you can easily apply this to subplot as well by replacing "nexttile" with "subplot(___)" and removing "tiledlayout".
x = rand(1,100)-.5 *10;
y = rand(1,100)-.5 * 5;
figure()
tiledlayout(1,2)
h(1) = nexttile;
plot(h(1), x,y,'o')
h(2) = nexttile;
plot(h(2), x,y,'o')
linkprop(h, {'xlim','ylim'})
% OR
% linkaxes(h)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/340855/image.gif)
댓글 수: 2
Adam Danz
2020년 8월 4일
편집: Adam Danz
2020년 8월 14일
H are the axis handles.
Example
h(1) = subplot(1,2,1);
h(2) = subplot(1,2,2):
linkaxes(h)
or
sp1 = subplot(1,2,1);
sp2 = subplot(1,2,2);
linkaxes([sp1,sp2])
Please take a moment to accept answers to your questions if the answers solved your problems. That's how the volunteers are 'thanked'. Here are your questions:
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!