1

我正在尝试在 Matlab 中绘制传记。我想显示节点的名称和每条边的标签。我正在设置特定边缘的标签。并设置传记的选项以显示边缘的标签,但它仍然没有显示它们。我错过了什么?有没有办法通过列表设置边缘的名称?还是你必须一一做?

谢谢你。

这是代码:

cm = sparse([0 1 1 0 0;1 0 0 1 1;1 0 0 0 0;0 0 0 0 1;1 0 1 0 0]);
names = {'E1','E2','E3','E4','E5'};
bg = biograph(cm,names,'LayoutType','radial','ShowTextInNodes','Label');
bg.nodes(1).Shape = 'circle'; 
bg.nodes(1).Size = [2 2];
bg.nodes(1).color = [.5 .7 1];
bg.edges(1).LineColor =[.5 .7 1];
bg.edges(1).Label = 'labelzz';
bg.edges(1).Description = 'Descriptionzz';
get(bg);
get(bg.edges(1));
gObj = view(bg);

这是结果:

Biograph object with 5 nodes and 9 edges.

               ID: ''

            Label: ''

      Description: ''

       LayoutType: 'radial'

      LayoutScale: 1

            Scale: 1

     NodeAutoSize: 'on'

  ShowTextInNodes: 'label'

         EdgeType: 'curved'

    EdgeTextColor: [0 0 0]

       ShowArrows: 'on'

        ArrowSize: 8

      ShowWeights: 'off'

     EdgeFontSize: 8

    NodeCallbacks: @(node)inspect(node)

    EdgeCallbacks: @(edge)inspect(edge)

CustomNodeDrawFcn: []

            Nodes: [5x1 biograph.node]

            Edges: [9x1 biograph.edge]

         ID: 'E1 -> E2'

      Label: 'labelzz'

Description: 'Descriptionzz'

     Weight: 1

  LineWidth: 0.5000

  LineColor: [0.5000 0.7000 1]

   UserData: []

图表图像:http://i.stack.imgur.com/n34Rt.png

4

2 回答 2

1

无法显示边缘标签或 ID。将传记属性 ShowWeights 设置为“on”,只能显示边缘权重。

于 2014-07-07T18:43:40.647 回答
1

Matlab 中的传记仅支持在边缘显示数字权重,但您可以轻松修改代码以显示任意文本。

在文件中:\toolbox\bioinfo\bioinfo\@biograph\@edge\hgUpdate.m

替换以下 2 行

set(h.hgline,'UserData',text(txy(1),txy(2),[' ' num2str(h.Weight) ' '] ,...

'String',[' ' num2str(h.Weight) ' '],...

经过

set(h.hgline,'UserData',text(txy(1),txy(2),[' ' h.Label ' '] ,...

'String',[' ' h.Label ' '],...

然后只需在边缘的“标签”属性中设置您的文本。例如

graph = biograph([0 1 ; 1 0], {'node1', 'node2'}, 'ShowWeights', 'on');
graph.Edges(1).Label = 'Edge 1-2';
graph.Edges(2).Label = 'Edge 2-1';
view(graph);
于 2016-05-25T06:12:41.470 回答