graphs in pyqt5

Solutions on MaxInterview for graphs in pyqt5 by the best coders in the world

showing results for - "graphs in pyqt5"
Maria
12 May 2017
1import sys
2import matplotlib
3matplotlib.use('Qt5Agg')
4
5from PyQt5 import QtCore, QtWidgets
6
7from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
8from matplotlib.figure import Figure
9
10
11class MplCanvas(FigureCanvasQTAgg):
12
13    def __init__(self, parent=None, width=5, height=4, dpi=100):
14        fig = Figure(figsize=(width, height), dpi=dpi)
15        self.axes = fig.add_subplot(111)
16        super(MplCanvas, self).__init__(fig)
17
18
19class MainWindow(QtWidgets.QMainWindow):
20
21    def __init__(self, *args, **kwargs):
22        super(MainWindow, self).__init__(*args, **kwargs)
23
24        # Create the maptlotlib FigureCanvas object, 
25        # which defines a single set of axes as self.axes.
26        sc = MplCanvas(self, width=5, height=4, dpi=100)
27        sc.axes.plot([0,1,2,3,4], [10,1,20,3,40])
28        self.setCentralWidget(sc)
29
30        self.show()
31
32
33app = QtWidgets.QApplication(sys.argv)
34w = MainWindow()
35app.exec_()
36