Visualizing flow through graph networks

조회 수: 3 (최근 30일)
Deepa Maheshvare
Deepa Maheshvare 2019년 11월 12일
댓글: Deepa Maheshvare 2019년 11월 13일
I've the following graph.
tail = 1:9;
head = 2:10;
G = graph(tail,head);
data = 1:10;
G.Nodes.Value = data';
p = plot(G)
p.Marker = 's';
p.MarkerSize = 7;
From the examples shown here, I could understand how linewidths of edges can be adjusted based edge weights. However,
in my example I have values assigned to nodes. I would like to change the color of nodes based on values stored in data.
Any suggestion on how this can be done?

답변 (1개)

Steven Lord
Steven Lord 2019년 11월 12일
Set the NodeCData property of the GraphPlot object.
p.NodeCData = G.Nodes.Value;
colorbar % to see the mapping between value and color
  댓글 수: 3
Steven Lord
Steven Lord 2019년 11월 12일
The corresponding property for edges is EdgeCData.
When you display p, you can see a list of some of the properties of the GraphPlot that you can query or change. There's also a link you can click to see more properties.
If you want more information about the values each of those properties can take and what each property means, see this documentation page. If you're using an older release you probably want to reference the properties link on the documentation page for GraphPlot instead of the online documentation for the current release, since we have added properties to the GraphPlot object in some recent releases.
doc GraphPlot
Deepa Maheshvare
Deepa Maheshvare 2019년 11월 13일
Thank you. I think I should be using caxis to set the scale of colorbar
When I try the following,
caxis([0 10])
The color of nodes vary from yellow to blue.
However, I would like to change the scale from gray to black. So, I tried changing the color of node
p.NodeColor = [0 0 0]; %black
I had expected the above would set the color scale to vary from gray to black. This didn't work either.
Any suggestions?

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

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by