我使用的是"plot_google_map.m",它使用Google Maps API在当前图形的背景中绘制地图.使用此图生成的图形会在缩放事件时自动刷新地图,并且我添加了一些代码以使其在平移事件时刷新数据.
现在我想以编程方式更改轴的范围而不使用缩放或平移按钮,但问题是地图不会自动刷新.所以,我正在考虑以编程方式生成缩放或平移事件,但我还没有找到一种方法.有什么想法吗?
让我详细说明我的问题.在'plot_google_map.m'中,有一个子函数,它是缩放事件的回调.
function plot_google_map
% Listen to Zoom events
h = figure(1); plot(1:10);
hz = zoom(h);
set(hz,'ActionPostCallback',@mypostcallback);
function mypostcallback(obj,evd)
disp('Refreshes map data');
Run Code Online (Sandbox Code Playgroud)
我想要做的是,在'plot_google_map'之外调用此子功能.
欢迎任何想法,并提前感谢您的答案!
假设您的轴句柄是,那么您可以通过更改轴的和属性而不是缩放比例来hAxes进行缩放,如下所示:xLimyLim
如果您的绘图使用 0-100 的 x 轴,那么您可以放大 0-100 的特定子范围,例如:
set(hAxes,'xLim',[20 40])
Run Code Online (Sandbox Code Playgroud)
对于 y 轴,您还可以缩放特定的 y 范围:
set(hAxes,'xLim',[30 70])
Run Code Online (Sandbox Code Playgroud)
如果您想放大绘图上的特定区域,例如 x[20-50],y[10-50],您可以通过执行前面的两个操作来实现,例如:
set(hAxes,'xLim',[20 50])
set(hAxes,'yLim',[10 50])
Run Code Online (Sandbox Code Playgroud)
因此,根据绘图或图像的大小更改轴的xLim和值,这就是轴缩放的实际工作方式。yLim
您甚至可以尝试这个演示脚本:
clear;clc;
figure;
h = axes;
y = sin( 0:2*pi / 100:pi );
plot(y);
%// =============================
pause(1);
set(h , 'xlim' , [20 80]);
%// =============================
pause(1);
set(h , 'xlim' , [30 40]);
%// =============================
pause(1);
set(h , 'xlim' , [10 100]);
%// =============================
pause(1);
set(h , 'ylim' , [.1 .4]);
%// =============================
pause(1);
set(h , 'ylim' , [.2 .7]);
%// =============================
pause(1);
set(h , 'ylim' , [.3 .9]);
%// =============================
pause(1);
set(h , 'ylim' , [.1 .2]);
set(h , 'xlim' , [10 80]);
%// =============================
pause(1);
set(h , 'ylim' , [.3 .7]);
set(h , 'xlim' , [40 90]);
%// =============================
Run Code Online (Sandbox Code Playgroud)