当前位置:网站首页>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等画图工具
代码人还是代码根据数据画点和线把,工具什么的太麻烦了,没试过
画图工具
边栏推荐
- 【OpenCV】形态学滤波(2):开运算、形态学梯度、顶帽、黑帽
- JESD204B时钟网络
- 项目实战 五 拟合直线 获得中线
- Etcd database source code analysis -- starting from the start function of raftnode
- Implementation of VGA protocol based on FPGA
- Ha Qu projection dark horse posture, only half a year to break through the 1000 yuan projector market!
- 学术报告系列(六) - Autonomous Driving on the journey to full autonomy
- 线性代数(一)
- 面试中有哪些经典的数据库问题?
- 安装mongodb数据库
猜你喜欢
MySQL卸载文档-Windows版
Force deduction 62 different paths (the number of all paths from the upper left to the lower right of the matrix) (dynamic planning)
MySQL installation
偏执的非合格公司
Redis(二)—Redis通用命令
二十岁的我4面拿到字节跳动offer,至今不敢相信
ETCD数据库源码分析——从raftNode的start函数说起
Common problems of caching in high concurrency scenarios
Apache ab 压力测试
Tkinter window selects PCD file and displays point cloud (open3d)
随机推荐
线性代数(一)
字符串常量与字符串对象分配内存时的区别
Developers don't miss it! Oar hacker marathon phase III chain oar track registration opens
Which foreign language periodicals are famous in geology?
直击2022ECDC萤石云开发者大会:携手千百行业加速智能升级
Common problems of caching in high concurrency scenarios
C language interview to write a function to find the first public string in two strings
VMware安装后打开就蓝屏
Overview of FlexRay communication protocol
Linear algebra (1)
Redis (I) -- getting to know redis for the first time
开发者别错过!飞桨黑客马拉松第三期链桨赛道报名开启
精准时空行程流调系统—基于UWB超高精度定位系统
学习笔记|数据小白使用DataEase制作数据大屏
Performance comparison between Ceres solver and g2o
Go straight to the 2022ecdc fluorite cloud Developer Conference: work with thousands of industries to accelerate intelligent upgrading
How to use wechat cloud hosting or cloud functions for cloud development of unapp development applet
怎样查找某个外文期刊的文献?
MySQL installation
JESD204B时钟网络