在Matlab中,如何放大脚本中的绘图 [英] In matlab, how can I zoom in on a plot in my script

查看:128
本文介绍了在Matlab中,如何放大脚本中的绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用脚本放大绘图.我只对水平约束缩放感兴趣.所以我想做类似的事情

I'd like to zoom in on a plot using a script. I'm only interested in horizontally constrained zooming. So I'd like to do something like

p = plot(myData);
z = zoom;
set(z, 'ZoomInToPoints' , [50 100]);

p = plot(myData);
myZoom([50, 100]);

因此,就像使用放大镜工具放大时一样,这些功能中的任何一个都可以放大绘图.我只指定两个点,因为我只想水平缩放.

So either of these functions would zoom into a plot like when you zoom in with the magnifying glass tool. I only specify two points because I only want to zoom horizontally.

注意,我已经尝试为此使用xlim.虽然有效,但它不允许我在绘图上使用命令text.

Note, I've already tried to use xlim for this. While it works, it doesn't let me use the command text on my plots, which I need.

推荐答案

调用text会将文本固定在图形上的一组特定坐标上.致电xlim后,您是否尝试过更新这些内容?

Calls to text will fix the text at a specific set of coordinates on the graph. Have you tried updating these after calling xlim?

编辑:您始终可以调整文本位置:

You can always adjust the text position:

x=1:.1:10;
y=sin(.1*x);
plot(x,y)
text(6,.8,'test') %#Sample figure

F=get(0,'children'); %#Figure handle
A=get(F,'Children'); %#Axes handle
T=findobj(A,'Type','text'); %# Text handle
oldxlim=xlim; %#grab the original x limits before zoom
oldpos=get(T,'Position'); %#get the old text position
set(A,'xlim',[5 15]); %#Adjust axes
newxlim=xlim;
newpos=[(oldpos(1)-oldxlim(1))*(diff(newxlim))...
/(diff(oldxlim))+newxlim(1) oldpos(2:end)]; 
%#interpolate to place the text at the same spot in the axes
set(T,'Position',newpos) %#Finally reset the text position

不漂亮,但是应该可以.如果每个轴或每个图形的轴有多个注释,则始终可以将以上代码循环插入.

Not pretty, but it should work. If you have more than one annotation per axes or axes per figure, you can always throw the above code in a loop.

这篇关于在Matlab中,如何放大脚本中的绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆