当前位置:网站首页>Networkx绘图和常用库函数坐标绘图
Networkx绘图和常用库函数坐标绘图
2022-07-07 02:18:00 【lanmy_dl】
说明:不是缝合,主要自己做笔记,最近了解的一个过程
1.图的创建
G = nx.Graph() # 创建无向图
G = nx.DiGraph() # 创建有向图
G = nx.MultiGraph() # 创建多重无向图
G = nx.MultiDigraph() # 创建多重有向图 AttributeError: module ‘networkx’ has no attribute ‘MultiDigraph’
G.clear() #清空图
2.Networkx绘图和整理功能的参数,networkx,画图,函数参数
3.Networkx库绘制有向图,自定义并固定各结点坐标
如果要用无向图,定义图的时候换就可,参考自下面
固定坐标
import networkx as nx
import matplotlib.pyplot as plt
def main():
G = nx.DiGraph()
# 添加对应的边和点
for i in range(1, 10):
G.add_node(i, desc='v'+str(i)) # 结点名称不能为str,desc为标签即结点名称
G.add_edge(1, 2, name='6') # 添加边, 参数name为边权值
G.add_edge(1, 3, name='4')
G.add_edge(1, 4, name='5')
G.add_edge(2, 5, name='1')
G.add_edge(3, 5, name='1')
G.add_edge(4, 6, name='2')
G.add_edge(5, 7, name='9')
G.add_edge(5, 8, name='7')
G.add_edge(6, 8, name='4')
G.add_edge(7, 9, name='2')
G.add_edge(8, 9, name='4')
pos = [(1, 3), (1, 3), (2, 4), (2, 2), (2, 1), (3, 3), (4, 1), (5, 4), (5, 2), (6, 3)] # pos列表从第0位开始,但我定义是从结点1开始,这里令前两个坐标相同
# 按pos所定位置画出节点,无标签无权值
nx.draw_networkx(G, pos, with_labels=None)
# 画出标签
node_labels = nx.get_node_attributes(G, 'desc')
nx.draw_networkx_labels(G, pos, labels=node_labels)
# 画出边权值
edge_labels = nx.get_edge_attributes(G, 'name')
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)
plt.title('AOE_CPM', fontsize=10)
plt.show()
if __name__ == '__main__':
main()
4.gephi、Graphviz等画图工具
代码人还是代码根据数据画点和线把,工具什么的太麻烦了,没试过
画图工具
边栏推荐
猜你喜欢
How can I check the DOI number of a foreign document?
Matlab / envi principal component analysis implementation and result analysis
Go straight to the 2022ecdc fluorite cloud Developer Conference: work with thousands of industries to accelerate intelligent upgrading
缓存在高并发场景下的常见问题
Software testing knowledge reserve: how much do you know about the basic knowledge of "login security"?
JMeter function assistant - random value, random string, fixed value random extraction
Redis(二)—Redis通用命令
Navicat importing 15g data reports an error [2013 - lost connection to MySQL server during query] [1153: got a packet bigger]
Can't you really do it when you are 35 years old?
Cloudcompare point pair selection
随机推荐
c面试 加密程序:由键盘输入明文,通过加密程序转换成密文并输出到屏幕上。
c语言(结构体)定义一个User结构体,含以下字段:
Common problems of caching in high concurrency scenarios
Leite smart home longhaiqi: from professional dimming to full house intelligence, 20 years of focus on professional achievements
安装mongodb数据库
Learning notes | data Xiaobai uses dataease to make a large data screen
Ant manor safety helmet 7.8 ant manor answer
Calculation model FPS
Install mongodb database
FPGA课程:JESD204B的应用场景(干货分享)
LM small programmable controller software (based on CoDeSys) Note 23: conversion of relative coordinates of servo motor operation (stepping motor) to absolute coordinates
隐马尔科夫模型(HMM)学习笔记
[FPGA] EEPROM based on I2C
Knight defeats demon king (Backpack & DP)
360 Zhiyu released 7.0 new products to create an exclusive "unified digital workspace" for the party, government and army, and central and state-owned enterprises
Developers don't miss it! Oar hacker marathon phase III chain oar track registration opens
Implementation of VGA protocol based on FPGA
程序员的日常 | 每日趣闻
C interview encryption program: input plaintext by keyboard, convert it into ciphertext through encryption program and output it to the screen.
地质学类比较有名的外文期刊有哪些?