Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ugeugeHigh
Created November 17, 2019 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugeugeHigh/8b553e5a64a2f5e27129313d3158a674 to your computer and use it in GitHub Desktop.
Save ugeugeHigh/8b553e5a64a2f5e27129313d3158a674 to your computer and use it in GitHub Desktop.
import sys
from PyQt5 import QtWidgets
from matplo_ui import Ui_Form
#below import libraries about matplotlib runing on pyqt5
import matplotlib
#Make sure that we are using QT5
matplotlib.use('Qt5Agg')
from PyQt5 import QtCore, QtWidgets
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import random
from numpy import arange, sin, pi
class MyMplCanvas(FigureCanvas):
def __init__(self, parent=None, width=10, height=8, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
self.compute_initial_figure()
FigureCanvas.__init__(self, fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
def compute_initial_figure(self):
pass
class MyStaticMplCanvas(MyMplCanvas):
def compute_initial_figure(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
self.axes.plot(t, s)
class Form(QtWidgets.QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
self.l = QtWidgets.QVBoxLayout(self.ui.widget)
def show_graph(self):
sc = MyStaticMplCanvas(self.ui.widget, width=5, height=4, dpi=100)
self.l.addWidget(sc)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = Form()
window.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment