I have an application with PyQt and I would like to add the Netgraph graphs interactiviness to my application.
However, I am not being able to click the vertex and edges of the graph.
Here is a minimal example:
import sys
import matplotlib
import matplotlib.pyplot as plt
from netgraph import InteractiveGraph
from PyQt5 import QtWidgets
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT
from matplotlib.figure import Figure
import networkx as nx
matplotlib.use('Qt5Agg')
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
g = nx.house_x_graph()
fig, ax = plt.subplots(figsize=(10, 10))
plot_instance = InteractiveGraph(g)
super(MplCanvas, self).__init__(fig)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
sc = MplCanvas(self, width=5, height=4, dpi=100)
toolbar = NavigationToolbar2QT(sc, self)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(sc)
widget = QtWidgets.QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
self.show()
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
app.exec_()
And here is an example with the behavior I want:
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()
Any ideas how I can make Netgraph interactiviness work along with PyQt?