필터 지우기
필터 지우기

How do I add both zoom and pan ability using mouse to a plot?

조회 수: 17 (최근 30일)
Magnu Blomberg
Magnu Blomberg 2016년 5월 18일
답변: Simon T 2019년 11월 2일
I have been trying to add both zoom and pan ability to a plot using the mouse scroll wheel and the drag to pan functionality. The area is a map and I would like the same kind of control as in Google Maps etc. I can achieve these functionalities separately with, e.g. the following code.
plot([0 10], [2 8]);
zoom on;
%pan on;
When I try to add both these, i.e. remove the comment, it fails and simply leaves me with the last specified functionality.
I tried to add the respective functionality on scroll wheel and click callbacks,
set(gcf,'WindowScrollWheelFcn', @scrollCb);
set(gcf,'WindowButtonDownFcn', @panCb);
where scrollCb is defined as
function scrollCb(obj, evnt)
zoom on;
display('zoom on');
and panCb with the corresponding code. This does not work and adding a new function callback within the function didn't work either.
Does anyone have a solution to this?
  댓글 수: 1
Adam
Adam 2016년 5월 18일
As far as I am aware the built-in pan and zoom modes are mutually exclusive. In essence though they just change the xlim and ylim properties of your image so you could program your own non-mutually exclusive versions attached to your callbacks.

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

답변 (1개)

Simon T
Simon T 2019년 11월 2일

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by