相关疑难解决方法(0)

用坐标绘制 NetworkX Graph

我的 networkx 图由具有名为“coords”(x,y) 的属性的对象组成:

import networkx as nx
import matplotlib.pyplot as plt

class device():
    def __init__(self, name):
        self.name = name
        self.coords = (0,0)
    def __repr__(self):
        return self.name

device1 =  device('1')
device1.coords = (20, 5)
device2 =  device('2')
device2.coords = (-4, 10.5)
device3 =  device('3')
device3.coords = (17, -5)

G = nx.Graph() 
G.add_nodes_from([device1, device2, device3])
nx.draw(G, with_labels = True)
plt.show()
Run Code Online (Sandbox Code Playgroud)

任何时候当我绘制它时,matplotlib 都会以混乱的顺序绘制图形。如何根据坐标绘制这样的图形?

python matplotlib networkx

2
推荐指数
1
解决办法
667
查看次数

标签 统计

matplotlib ×1

networkx ×1

python ×1