Pyqt和Netgraph Edistic图
我已经有一个与NetGraph一起工作的PYQT应用程序。
给定以下代码,我能够移动顶点和边缘:
import sys
from PyQt5 import QtWidgets
import matplotlib
matplotlib.use("Qt5Agg")
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT
from matplotlib.figure import Figure
from netgraph import InteractiveGraph
import networkx as nx
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
super(MplCanvas, self).__init__(Figure(figsize=(width, height), dpi=dpi))
self.setParent(parent)
self.ax = self.figure.add_subplot(111)
graph = nx.house_x_graph()
self.plot_instance = InteractiveGraph(graph, ax=self.ax)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.canvas = MplCanvas(self, width=5, height=4, dpi=100)
self.toolbar = NavigationToolbar2QT(self.canvas, self)
widget = QtWidgets.QWidget()
self.setCentralWidget(widget)
layout = QtWidgets.QVBoxLayout(widget)
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
def main():
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec_()
if __name__ == "__main__":
main()
例如,Netgraph Editailgraph允许添加或删除顶点和边缘。但是,在上一个代码中,如果从InteractiveGraph
更改为Editablegraph
,则什么都不会更改。
如果运行以下示例:
import matplotlib.pyplot as plt
import networkx as nx
from netgraph import EditableGraph
g = nx.house_x_graph()
fig, ax = plt.subplots(figsize=(10, 10))
plot_instance = EditableGraph(g)
plt.show()
单击每个顶点或边缘,然后按删除按钮,将被删除。
我希望在PYQT窗口中使用相同的行为。我不确定缺少什么。
I already have an PyQt application working along with Netgraph.
I am able to move vertex and edges, given the following code:
import sys
from PyQt5 import QtWidgets
import matplotlib
matplotlib.use("Qt5Agg")
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT
from matplotlib.figure import Figure
from netgraph import InteractiveGraph
import networkx as nx
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
super(MplCanvas, self).__init__(Figure(figsize=(width, height), dpi=dpi))
self.setParent(parent)
self.ax = self.figure.add_subplot(111)
graph = nx.house_x_graph()
self.plot_instance = InteractiveGraph(graph, ax=self.ax)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.canvas = MplCanvas(self, width=5, height=4, dpi=100)
self.toolbar = NavigationToolbar2QT(self.canvas, self)
widget = QtWidgets.QWidget()
self.setCentralWidget(widget)
layout = QtWidgets.QVBoxLayout(widget)
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
def main():
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec_()
if __name__ == "__main__":
main()
Netgraph EditableGraph allows to add or remove vertex and edges, for example. However, in the previous code, if changed from InteractiveGraph
to EditableGraph
, nothing is changed.
If you run the following example:
import matplotlib.pyplot as plt
import networkx as nx
from netgraph import EditableGraph
g = nx.house_x_graph()
fig, ax = plt.subplots(figsize=(10, 10))
plot_instance = EditableGraph(g)
plt.show()
Click on every vertex or edge, and then press the delete button, it will be erased.
I want this same behavior inside a PyQt window. I am not sure what is missing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在打开 netgraph repo 上的问题时得到了一些帮助,最终得到了以下算法:
I got some help opening an issue at netgraph repo and I ended up with the following algorithm: