【发布时间】:2020-08-18 17:52:16
【问题描述】:
所以我试图在 Python 中使用 NetworkX 生成一个六边形晶格。使用代码后:
G = nx.hexagonal_lattice_graph(m=2, n=2, periodic=False, with_positions=True, create_using=None)
plt.subplot(111)
nx.draw(G, with_labels=True, font_weight='bold')
plt.show()
我得到一个六边形格子,看起来像这样: lattice
如您所见,这个格子是由不规则的六边形组成的,每次运行代码时,形状都会发生变化。有没有办法使用 NetworkX 生成完美的六边形点阵,即 this,但只有 X 个六边形?
谢谢!
【问题讨论】:
-
我建议将图像嵌入问题中。
-
答案是肯定的,您需要在
nx.draw()中使用pos参数来定义顶点的确切位置。
标签: python networkx physics lattice