Matplotlib – 绘制 Networkx 的网格和图表
若要使用 networkx 绘制网格和图表,我们可以按以下步骤操作:
- 导入 networkx 和 pyplot。
- 设置图纸大小,并调整子图间及周围的内边距。
- 使用 nx.grid_2d_graph(3, 3) 获取一个二维网格图。网格图使每个节点都与其四个最近的邻居相连。
- 使用 Matplotlib 绘制图 G。
- 若要显示图纸,请使用 show() 方法。
示例
# Import networkx and pyplot import networkx as nx from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Draw the graph G = nx.grid_2d_graph(3, 3) nx.draw(G, node_size=100) plt.show()
输出
它将生成以下输出


广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP