2017-02-14 59 views
2

我想從MATLAB圖中獲取軸TickValues的位置。例如,我有一個數字,如下所示:在MATLAB圖中查找軸TickValues的位置

MATLAB Figure

我試圖找到軸TickValues的位置後,我圖保存爲圖像(圖中示出)。[注:該包圍盒的手工。忽略任何錯誤]

axis TickValue Location

這裏是我產生至今代碼:

h = plot(1:10); 
hFrame = getframe(h.Parent.Parent); 
hImage = hFrame.cdata; 
set(h.Parent,'Units','pixel'); 

我試圖從上hImage得到邊界爲x軸TickValues和y軸TickValues箱h.Parent的position

讓我知道如果問題還不清楚。我會編輯以使其更清晰。

+0

什麼是你真正想實現什麼?這似乎是一種非常圓滑的方式。 – Suever

+0

我試圖從手柄中獲取圖像中的那些區域(需要以像素爲單位),因爲我們知道圖像通常以像素爲單位。那些提取的地區將在未來用於其他目的。關鍵是從圖形處理信息中提取圖像。我不明白它是如何完成的。 – user7410580

+0

爲什麼不使用'getframe(h.Parent)'來保存不包含標籤的部分?如果你只是想要「軸」的位置,你可能不需要保存圖像。只需使用'h.Parent.Position'來獲取它。 – Suever

回答

1

由於@suever suggested in comments,軸的Position屬性將是做到這一點的最簡單的方法:

h = plot(1:10); 
pos = h.Parent.Position; % get the axes position 
m = 3; % width and hight multiplyer 
xth = h.Parent.XAxis.TickLength(2); % get x-axis tick hight 
dimx = [pos(1)-xth pos(2)-xth*m pos(3)+xth*2 xth*m]; 
annotation('rectangle',dimx,'color','r') % for demonstration 
yth = h.Parent.YAxis.TickLength(2); % get y-axis tick hight 
dimy = [pos(1)-yth*(m-1) pos(2)-yth yth*(m-1) pos(4)+yth*2]; 
annotation('rectangle',dimy,'color','r') % for demonstration 

示範:

axis_position

,你可以改變m,以確保所有的刻度值都在邊界框內。


編輯:

選項2:

op2

方案3:

op3

+0

這是一個很好但不安靜的優雅解決方案。這是一種解決方法。如果我們看看你的情況,就會有重疊。如果我將乘數更改爲1,它實際上高於tickValues – user7410580

+0

@ user7410580我看不出它們如何重疊?你能畫這個嗎? – EBH

+0

可能是我在重疊部分錯了;但我正在尋找一個解決方案,其中包含一個專門爲軸值分配的區域。 – user7410580