2017-06-22 103 views
0

我想要在Octave中可視化有向無環圖樹。在Octave中顯示有向無環圖

在MATLAB中,這是使用biograph()完成的。是否有八度相當的?

另外,如何使用Octave的drawgraph()

回答

1

drawGraph(從geometry包)接受:

  • 一個「節點」矩陣,其中每一行是代表單個節點
  • 一個「邊緣」矩陣,其中每一行代表一組座標兩個節點之間的邊緣,其中節點由「節點」矩陣中的對應行在數字上標識。

實施例:

pkg load geometry; 

Nodes = [ 0, -1; 
      1, 0; 
      0, 1; 
     -1, 0]; 

Edges = [1, 2; 
     2, 3; 
     3, 4; 
     1, 3; 
     2, 4]; 

g = drawGraph(Nodes, Edges); 
set(g, 'markerfacecolor', 'g', 'markersize', 50, 'linewidth', 5); 

然而,這是從字面上只是一個帶標記線的集合。您可以使用簡單的lineplot命令(或quiver,如果您還需要箭頭)以簡單的循環方式輕鬆地複製它。

Nodes(1) = struct('coords', [0, -1], 'shape', 'o', 'text', 'Node 1', 'facecolor', 'k', 'edgecolor', 'r', 'textcolor', 'g', 'size', 75); 
Nodes(2) = struct('coords', [1, 0], 'shape', 'd', 'text', 'Node 2', 'facecolor', 'r', 'edgecolor', 'g', 'textcolor', 'b', 'size', 100); 
Nodes(3) = struct('coords', [0, 1], 'shape', 's', 'text', 'Node 3', 'facecolor', 'g', 'edgecolor', 'b', 'textcolor', 'k', 'size', 75); 
Nodes(4) = struct('coords', [-1, 0], 'shape', 'p', 'text', 'Node 4', 'facecolor', 'b', 'edgecolor', 'k', 'textcolor', 'r', 'size', 150); 

NodesLayer = axes(); 
hold on; 
for i = Nodes 
    Node = plot(i.coords(1), i.coords(2)); 
    set (Node, 'marker', i.shape, 'markerfacecolor', i.facecolor, 'markeredgecolor', i.edgecolor', 'markersize', i.size, 'linewidth', 5); 
end 
hold off; axis off; 
set(NodesLayer, 'xlim', [-1.5, 1.5], 'ylim', [-1.5, 1.5]); 

TextLayer = axes('color', 'none'); 
for i = Nodes 
    Text = text (i.coords(1)-0.16, i.coords(2), i.text); 
    set (Text, 'color', i.textcolor, 'fontsize', 12, 'fontweight', 'bold'); 
end 
hold off; axis off; 
set(TextLayer, 'xlim', [-1.5, 1.5], 'ylim', [-1.5, 1.5]); 

Edges = [1,2; 2,3; 3,4; 4,1; 2,1; 4,3; 1,3; 3,1]; 

EdgesLayer = axes('color', 'none') 
hold on; 
for E = Edges.' 
    i = E(1); j = E(2); 
    u = [Nodes(j).coords(1) - Nodes(i).coords(1)]; 
    v = [Nodes(j).coords(2) - Nodes(i).coords(2)]; 
    x = Nodes(i).coords(1) + u * 0.25; 
    y = Nodes(i).coords(2) + v * 0.25; 
    Q = quiver(x, y, u * 0.5, v * 0.5, 0.1); 
    set (Q, 'linewidth', 3, 'color', 'k'); 
end 
hold off; axis off; 
set (EdgesLayer, 'xlim', [-1.5, 1.5], 'ylim', [-1.5, 1.5]); 

+0

它幫助我的問題:如果你想用不同的形狀,顏色,文字等

這裏有一個手動例如節點,這可能是可取的。不過,我想改變從matriks看圖。作爲節點Y的列,作爲節點X的列,以及作爲邊的權重的矩陣的值。 例如 我想在matlab中顯示graf matriks K = [0 3 4; 0 0 2; 0 0 0; in matlab K = [0 3 4; 0 0 2; 0 0 0]; view(biograph(K,[],'ShowArrows','off','ShowWeights','on')) 在matlab中工作,但不工作在八度。我必須做些什麼來解決這個問題 – Dafri