【发布时间】:2018-12-25 23:20:30
【问题描述】:
这是我第一次在 stackoverflow 上发布内容,如果帖子质量不高,请见谅。
我正在尝试在 MATLAB 中制作一个图形,其中一些相互连接的节点排列成一个圆圈,我想标记每个节点(例如,1 2 3 等)。当我使用此示例代码并注释掉“旋转”(最后一行)时,我得到对齐错误的文本标签。我该怎么做才能让它们与节点图等距放置而无需旋转文本?谢谢大家! (我附上代码生成的图)。
%# 60-by-60 sparse adjacency matrix
A = bucky();
N = length(A);![enter image description here][1]
%# x/y coordinates of nodes in a circular layout
r = 1;
theta = linspace(0,2*pi,N+1)'; theta(end) = [];
xy = r .* [cos(theta) sin(theta)];
%# labels of nodes
txt = cellstr(num2str((1:N)','%02d'));
%# show nodes and edges
figure(123)
line(xy(:,1), xy(:,2), 'LineStyle','none', ...
'Marker','.', 'MarkerSize',15, 'Color','g')
hold on
gplot(A, xy, 'b-')
axis([-1 1 -1 1]); axis equal off
hold off
%# show node labels
h = text(xy(:,1).*1.05, xy(:,2).*1.05, txt, 'FontSize',8);
%set(h, {'Rotation'},num2cell(theta*180/pi))
【问题讨论】:
标签: matlab plot text placement