MATLAB: Hi.how i can draw a graph like this? that have pyramid shape.the links between nodes have different thickness and darkness.

graphplot

Best Answer

When you use numeric vectors as your source and target inputs, MATLAB assumes you want one node for each integer value from 1 to the maximum value stored in either s or t, whichever is greater. So since t has a maximum value of 65, your graph will have 65 nodes.
Since I suspect the values in s and t are meant to be identifiers, not node numbers (you wouldn't add 1 to an element of s and necessarily expect it to mean something, right?) I would convert them into text data.
s = [11 11 21 22 22 31 32 33 31 41 41 42 43 44 51 52 53 53 54 55];
t = [21 22 31 32 33 41 42 43 44 51 55 52 53 54 61 62 63 66 64 65];
weights = [50 10 20 80 90 60 40 50 20 10 11 12 13 14 15 16 17 18 19 20];
sc = arrayfun(@num2str, s, 'UniformOutput', false);
tc = arrayfun(@num2str, t, 'UniformOutput', false);
G = graph(sc, tc, weights);
h = plot(G, 'layout', 'layered')
This doesn't look exactly like the picture you showed, but it's closer. If you want finer-grained control over exactly where the nodes appear, change the XData and YData properties of the GraphPlot object h or call plot with the 'XData' and 'YData' parameters. For instance, to stretch the Y axes a bit and give extra spacing between the levels:
figure
h2 = plot(G, 'XData', 2*h.XData, 'YData', h.YData.^2)
You can even tweak one or two points, if the 'layered' layout gets you close to what you want.
% Find nodes '42', '43', and '44'
n = findnode(G, {'42', '43', '44'});
% Move '42' into the position previously occupied by '43'
% Move '43' into the position previously occupied by '44'
% Move '44' into the position previously occupied by '42'
h.XData(n) = h.XData(n([2 3 1]));
Now, if you still want to represent some quality of the edges using thickness, use the highlight function on the GraphPlot object (not the graph or digraph itself.)
highlight(h, '11', 'NodeColor', 'r')
highlight(h, '11', '21', 'EdgeColor', 'k')