2010-08-02 114 views
4

我想使用腳本放大繪圖。我只對水平約束縮放感興趣。所以我想這樣做在matlab中,如何放大腳本中的圖形

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

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

因此,無論這些功能將放大到當你用放大鏡工具放大像一個陰謀。我只指定兩點,因爲我只想水平放大。

請注意,我已經嘗試過使用xlim。雖然它起作用,但它不允許我在我需要的地塊上使用命令text

+0

你是什麼意思「它不讓我使用命令'文本'」後使用'xlim'?函數'xlim'只需設置x軸限制。它不應該影響對「文本」的調用。 – gnovice 2010-08-02 17:49:03

+0

沒有任何文字實際顯示在情節中。它可能仍在工作,但將文本放在錯誤的地方。 – devin 2010-08-02 18:58:18

+0

我很漂亮變焦不會解決你的問題。您必須編輯文本位置。 – Doresoom 2010-08-02 19:06:13

回答

2

調用text會將文本固定在圖形上的一組特定座標上。你有沒有嘗試更新這些後調用xlim?

編輯:您可以隨時調整文本的位置:

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 

不漂亮,但它應該工作。如果每個圖形的每個軸或軸有多個註釋,則始終可以將上述代碼放在一個循環中。

+0

我有太多的電話來改變它們。 – devin 2010-08-02 18:56:53

1

textxlim有什麼問題?這不是你想要的行爲類型嗎?

plot(1:100,randn(100,1)) 
text(80,1.5,'text') 
set(gca,'XLim',[70 100]) % notice that text stays at same point in "data space" but moves in "axis space" 
text(80,1,'text2'); % new text appears in axis space as well 

如果我誤解,你希望文本在您的軸線空間的特定點(不是數據空間text使用),不論如何放大你是,你可以創建另一組軸的出現爲你的文字:

inset_h = axes('position',[0.5 0.5 0.2 0.2]) 
set(inset_h,'Color','none'); axis off 
text(0,0,'text') 
相關問題