[英]How can I make a plot representing connection relationship with python matplotlib?
I want to make a plot like this with python, I searched in matplotlib Gallery but can't find any similar one:我想用 python 制作一个像这样的 plot,我在 matplotlib Gallery 中搜索但找不到任何类似的:
The plot is made based on 2D matrix. plot 是基于二维矩阵制作的。 For example, I have a 5*5 matrix, symmetric about the diagonal:例如,我有一个 5*5 的矩阵,关于对角线对称:
Connection = np.array([0,0,1,1,1],
[0,0,1,0,1],
[1,1,0,1,0],
[1,0,1,0,0],
[1,1,0,0,0])
The element represent the connections relationships, if Connection[ i ][ j ] = 0
, means no connections between dot i and dot j
.该元素表示连接关系,如果Connection[ i ][ j ] = 0
,则表示dot i and dot j
之间没有连接。 If Connection[ i ][ j ] = 1
, then there should be a connection line between dot i and j
如果Connection[ i ][ j ] = 1
,那么dot i and j
之间应该有一条连接线
Since it's a bidirectional relation and the matrix is symmetric, if dot 1 has connection with dot 3, then dot 3 should also has connection with dot 1.由于它是双向关系且矩阵是对称的,如果点 1 与点 3 有联系,那么点 3 也应该与点 1 有联系。
For the matrix given, the expected plot should looks like(I made this by powerpoint):对于给定的矩阵,预期的 plot 应该看起来像(我通过 powerpoint 制作的):
How can I make this kind plots?我怎样才能制作这种情节? Thanks in advance!提前致谢!
It can be solved by networkx package可以通过networkx package解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.