Jas*_*n S 6 matlab graphing annotations
我想在图表上放一个带圆圈的数字作为标记靠近(但不是在点).听起来很简单,但我也希望变焦/宽高比变化不变.
由于这个不变量,我无法将圆形绘制为线对象(无需在重新缩放时重绘它); 如果我使用圆形标记,我必须在重新缩放时调整其偏移量.
我能想到的最简单的方法是在text()函数的字符串中使用Unicode或Wingdings字符①②③等.但unicode似乎不能正常工作,以下示例仅适用于①而不适用于其他数字(产生矩形框):
作品:
clf; text(0.5,0.5,char(129),'FontName','WingDings')
Run Code Online (Sandbox Code Playgroud)
不起作用(应该是带圆圈的2):
clf; text(0.5,0.5,char(130),'FontName','WingDings')
Run Code Online (Sandbox Code Playgroud)
什么给了,有人可以建议一个解决方法吗?
这似乎对我有用,使用Matlab的乳胶解释器,并且\textcircled:
clf; text(0.5, 0.5, '$\textcircled{2}$', 'Interpreter', 'latex')
Run Code Online (Sandbox Code Playgroud)
该\textcircled命令似乎有一些偏移问题,也许你可以尝试改进使用的latex命令,让我们知道:)
例如,按照上述链接,我得到了更好的结果:
clf; text(0.5, 0.5, '$\raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {2}}}$', 'Interpreter', 'latex')
Run Code Online (Sandbox Code Playgroud)
但是,两位数的数字看起来很糟糕.
下面是一个示例,其中标记(文本+圆圈)对于缩放/调整大小是不变的:
%# 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)
Run Code Online (Sandbox Code Playgroud)

比较@catchmeifyoutry提出的基于LaTeX的解决方案(注意两位数字):
%# 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)
Run Code Online (Sandbox Code Playgroud)
