0
我想要在Octave中可視化有向無環圖樹。在Octave中顯示有向無環圖
在MATLAB中,這是使用biograph()
完成的。是否有八度相當的?
另外,如何使用Octave的drawgraph()
?
我想要在Octave中可視化有向無環圖樹。在Octave中顯示有向無環圖
在MATLAB中,這是使用biograph()
完成的。是否有八度相當的?
另外,如何使用Octave的drawgraph()
?
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);
然而,這是從字面上只是一個帶標記線的集合。您可以使用簡單的line
和plot
命令(或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]);
它幫助我的問題:如果你想用不同的形狀,顏色,文字等
這裏有一個手動例如節點,這可能是可取的。不過,我想改變從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