필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
  댓글 수: 2
John D'Errico
John D'Errico 2018년 2월 16일
편집: John D'Errico 2018년 2월 16일
What have you tried? If nothing, then why not? Have you tried using line? plot or even patch? You need to learn to use the graphics tools, things that allow you to specify and change aspects of a plotted line.
I would suggest however, line thickness is not a good thing to vary here, since that thickness is not easy to discern. A far better choice would be to use a fixed thickness, but use color variations to distinguish the different edges. Color is far easier to see a subtle difference, something you would never recognize from only a subtle change in thickness, if at all.
ali jafari
ali jafari 2018년 2월 16일
thanks. i wrote this code. and plot this figure but the some nodes are useless. the thickness show the degree of similarity between the nodes. your suggest is very good. pleas suggest a code to me.thank u.
if true
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];
G = graph(s,t,weights);
plot(G)
end
{
}

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2018년 2월 16일
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')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by