当前位置:网站首页>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等画图工具
代码人还是代码根据数据画点和线把,工具什么的太麻烦了,没试过
画图工具
边栏推荐
- 途家、木鸟、美团……民宿暑期战事将起
- Postgresql源码(60)事务系统总结
- ICML 2022 | explore the best architecture and training method of language model
- Leite smart home longhaiqi: from professional dimming to full house intelligence, 20 years of focus on professional achievements
- Audio distortion analysis of DSP and DAC based on adau1452
- Redis(一)——初识Redis
- Which foreign language periodicals are famous in geology?
- 线性代数(一)
- ceres-solver和g2o性能比较
- 面试中有哪些经典的数据库问题?
猜你喜欢
FPGA课程:JESD204B的应用场景(干货分享)
How to set up in touch designer 2022 to solve the problem that leap motion is not recognized?
Go straight to the 2022ecdc fluorite cloud Developer Conference: work with thousands of industries to accelerate intelligent upgrading
屏幕程序用串口无法调试情况
LM11丨重构K线构建择时交易策略
JWT 认证
Experience sharing of contribution of "management world"
软件测试到了35岁,真的就干不动了吗?
循环肿瘤细胞——Abnova 解决方案来啦
「运维有小邓」符合GDPR的合规要求
随机推荐
Crudini profile editing tool
VMware安装后打开就蓝屏
How to keep accounts of expenses in life
Postgresql中procedure支持事务语法(实例&分析)
Programmers' daily | daily anecdotes
一段程序让你明白什么静态内部类,局部内部类,匿名内部类
程序员的日常 | 每日趣闻
Calculation model FPS
Abnova循环肿瘤DNA丨全血分离,基因组DNA萃取分析
C interview 24 (pointer) define a double array with 20 elements a
Installing redis and windows extension method under win system
线性代数(一)
Problems and precautions about using data pumps (expdp, impdp) to export and import large capacity tables in Oracle migration
Abnova 免疫组化服务解决方案
如何解决数据库插入数据显示SQLSTATE[HY000]: General error: 1364 Field ‘xxxxx‘ doesn‘t have a default value错误
MySQL卸载文档-Windows版
Can't you really do it when you are 35 years old?
Experience sharing of contribution of "management world"
肿瘤免疫治疗研究丨ProSci LAG3抗体解决方案
反射(二)