以节点之间的链接绘制圆形节点网络 [英] Drawing a network of nodes in circular formation with links between nodes

查看:39
本文介绍了以节点之间的链接绘制圆形节点网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个节点的圆形图,其中某些节点之间有链接.以下是社交网络图表中的一些示例:


(来源:
(来源:twit88.com)

如何使用 MATLAB 完成此操作?是否可以不安装单独的软件包?

解决方案

这是您可以随心所欲的一种方法.首先,在你感兴趣的圆上生成点

clear;theta=linspace(0,2*pi,31);theta=theta(1:end-1);[x,y]=pol2cart(theta,1);

接下来,如果您知道连接的节点对,则可以跳过此步骤.但在许多情况下,您可以从其他计算中获得连接矩阵,然后从中找到连接节点的索引.在这里,我创建了一个布尔连接矩阵.因此,如果有 N 个节点,则连通矩阵是一个 NxN 对称矩阵,其中如果 i,jth 个元素是 1,这意味着你有一个从节点 i 到节点 j0 的连接,否则.然后您可以提取非零对的下标以获得节点连接(只需要上三角形).

links=triu(round(rand(length(theta))));%# 这是一个随机的连接列表[ind1,ind2]=ind2sub(size(links),find(links(:)));

这是我用上面的代码生成的连接矩阵.

现在我们只需要绘制连接,一次一个

h=figure(1);clf(h);plot(x,y,'.k','markersize',20);坚持arrayfun(@(p,q)line([x(p),x(q)],[y(p),y(q)]),ind1,ind2);轴等于关闭

这会给你一个类似于你的例子的数字

I would like to draw a circular graph of nodes where certain nodes have a link between them. Here are a few examples from social network graphs:


(source: wrightresult.com)


(source: twit88.com)

How can this be done with MATLAB? Is it possible without installing a separate package?

解决方案

Here is one way you can do what you want. First, generate points on the circle that you are interested in

clear;
theta=linspace(0,2*pi,31);theta=theta(1:end-1);
[x,y]=pol2cart(theta,1);

Next, if you know the pairs of nodes that are connected, you can skip this step. But in many cases, you get a connectivity matrix from other computations, and you find the indices of the connected nodes from that. Here, I've created a Boolean matrix of connections. So, if there are N nodes, the connectivity matrix is an NxN symmetric matrix, where if the i,jth element is 1, it means you have a connection from node i to node j and 0 otherwise. You can then extract the subscripts of the non-zero pairs to get node connections (only the upper triangle is needed).

links=triu(round(rand(length(theta))));%# this is a random list of connections
[ind1,ind2]=ind2sub(size(links),find(links(:)));

This is the connectivity matrix I generated with the code above.

Now we just need to plot the connections, one at a time

h=figure(1);clf(h);
plot(x,y,'.k','markersize',20);hold on
arrayfun(@(p,q)line([x(p),x(q)],[y(p),y(q)]),ind1,ind2);
axis equal off

which will give you a figure similar to your examples

这篇关于以节点之间的链接绘制圆形节点网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆