2012-05-30 30 views
6

我想提出一個圓圈的數字在圖上作爲標記附近(但不是)一個點。聽起來很簡單,但我也希望變焦/縱橫比變化不變。MATLAB:將被圈住的數字到圖形

由於這種不變的,我不能畫一個圓作爲線對象(不重繪時重新調整);如果我使用圓形標記,則必須在重新縮放後調整它的偏移量。

我能想到的最簡單的方法是使用Unicode或宋體字① ② ③等等在一個字符串中用於text()函數。但是unicode似乎並不正確,下面的示例只適用於①而不是其他數字(其產生的矩形框):

作品:

clf; text(0.5,0.5,char(129),'FontName','WingDings') 

不工作(應該是一個圓圈2):

clf; text(0.5,0.5,char(130),'FontName','WingDings') 

是什麼給了,並能任何人都會提出一種解決方法?

回答

8

這似乎爲我工作,使用Matlab的乳膠解釋,並\textcircled

clf; text(0.5, 0.5, '$\textcircled{2}$', 'Interpreter', 'latex') 

\textcircled命令似乎有一些offset problems,也許你可以嘗試提高使用的乳膠命令,讓我們知道:)

按照上面的鏈接,例如,我得到更好的結果:

clf; text(0.5, 0.5, '$\raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {2}}}$', 'Interpreter', 'latex') 

儘管如此,兩位數數字看起來很糟糕。

+0

甜美!!!!!!!這真的有幫助。謝謝 - 我知道TeX中的一些基礎知識,但在過去的10年中一直沒有使用它。一旦我發現我的腦細胞太多以至於不熟悉我經常使用的工具,我就停止使用它。 :-( –

+0

很高興幫助:) – catchmeifyoutry

6

這裏就是標記(文本+圓圈)是不變的縮放的示例/調整:

%# some graph in 2D 
[adj,XY] = bucky; 
N = 30; 
adj = adj(1:N,1:N); 
XY = XY(1:N,1:2); 

%# plot edges 
[xx yy] = gplot(adj, XY); 
hFig = figure(); axis equal 
line(xx, yy, 'LineStyle','-', 'Color','b', 'Marker','s', 'MarkerFaceColor','g') 

%# draw text near vertices 
xoff = 0; yoff = 0;  %# optional offsets 
str = strtrim(cellstr(num2str((1:N)'))); 
hTxt = text(XY(:,1)+xoff, XY(:,2)+yoff, str, ... 
    'FontSize',12, 'FontWeight','bold', ... 
    'HorizontalAlign','right', 'VerticalAlign','bottom'); 

%# draw circles around text 
e = cell2mat(get(hTxt, {'Extent'})); 
p = e(:,1:2) + e(:,3:4)./2; 
hLine = line('XData',p(:,1), 'YData',p(:,2), ... 
    'LineStyle','none', 'Marker','o', 'MarkerSize',18, ... 
    'MarkerFaceColor','none', 'MarkerEdgeColor','k'); 

%# link circles position to text (on zoom and figure resize) 
callbackFcn = @(o,e) set(hLine, ... 
    'XData',cellfun(@(x)x(1)+x(3)/2,get(hTxt,{'Extent'})), ... 
    'YData',cellfun(@(x)x(2)+x(4)/2,get(hTxt,{'Extent'}))); 
set(zoom(hFig), 'ActionPostCallback',callbackFcn) 
set(hFig, 'ResizeFcn',callbackFcn) 

screenshot

比較針對@catchmeifyoutry建議(注意基於乳膠液後兩位數字):

%# use LaTeX to draw circled text at vertices 
%#str = num2str((1:N)', '$\\textcircled{%d}$'); 
str = num2str((1:N)', '$\\raisebox{.5pt}{\\textcircled{\\raisebox{-.9pt} {%d}}}$'); 
text(XY(:,1), XY(:,2), str, ... 
    'HorizontalAlign','right', 'VerticalAlign','bottom', ... 
    'Interpreter','latex', 'FontSize',18) 

screenshot_latex

+0

哦,有趣!當我有機會的時候,我必須嘗試一下。 –