我有两个函数可以在networkx中绘制不同的图形来绘制伦敦地铁上的列车线。它工作正常,但我想把它移到一个tkinter窗口。我有一套窗户,每列火车都有不同的框架。我只是不知道如何将这两个函数集成到窗口中! 下面是我用来绘制图表的函数:
def drawPiccadilly(pos):
#a dictionary declaring the labels for each node
labels = {"Uxbridge(P)":"Uxbridge", "Rayners Lane(P)":"Rayners Lane", "Ealing Common(P)":"Ealing Common", "South Ealing(P)":"South Ealing", "Heathrow(P)":"Heathrow", "Hammersmith(P)":"Hammersmith", "Earls Court(P)":"Earls Court",
"South Kensington(P)":"South Kensington", "Green Park(P)":"Green Park", "Piccadilly Circus(P)":"Piccadilly Circus", "Leicester Square(P)":"Leicester Square", "Holborn(P)":"Holborn", "Kings Cross St Pancras(P)":"Kings Cross St Pancras", "Finsbury Park(P)":"Finsbury Park", "Cockfosters(P)":"Cockfosters"}
#a dictionary declaring the label positions
PLabelPos = {"Uxbridge(P)":(-1300,1000), "Rayners Lane(P)":(-1100,1000), "Ealing Common(P)":(-1100,-100), "South Ealing(P)":(-1200,-400), "Heathrow(P)":(-1200,-750), "Hammersmith(P)":(-900,-250), "Earls Court(P)":(-700,-300),
"South Kensington(P)":(-400,-600), "Green Park(P)":(-100,-300), "Piccadilly Circus(P)":(0,100), "Leicester Square(P)":(300,-200), "Holborn(P)":(500,500), "Kings Cross St Pancras(P)":(500,1000), "Finsbury Park(P)":(60,1200), "Cockfosters(P)":(600,1350)}
#drawing the Piccadilly graph
networkx.draw(Piccadilly, pos, node_color="purple", edge_color="blue", node_size = 100)
networkx.draw_networkx_labels(Piccadilly, PLabelPos, labels, font_size=6)
我的窗口非常通用,只是一个容器和一些在框架之间切换的按钮。 这是我试图做的,但就是不起作用。它要么出现属性错误,要么“模块中不存在图形”
def drawPiccadilly():
f = plt.Figure(figsize=(5,5), dpi=100)
a = f.add_subplot(111)
a.plot()
a.draw(Piccadilly, node_color="purple", edge_color="blue", node_size = 100)
if __name__ == '__main__':
app = Window()
app.mainloop()
目前没有回答
相关问题 更多 >
编程相关推荐