SHARE
TWEET

Untitled

a guest Jun 20th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. from PyQt5 import QtGui,QtCore, QtWidgets,QtMultimedia, QtMultimediaWidgets
  3. from PyQt5.QtWidgets import QDialog, QApplication, QVBoxLayout
  4. from PyQt5.QtCore import Qt
  5. from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
  6. from matplotlib.backends.backend_qt5 import NavigationToolbar2QT as NavigationToolbar
  7. from matplotlib.figure import Figure
  8. import matplotlib.pyplot as plt
  9.  
  10. import numpy as np
  11.  
  12.  
  13. class MyCanvas(FigureCanvas):
  14.     def __init__(self, parent=None, width=5, height=4, dpi=100):
  15.         fig = Figure(figsize=(width, height), dpi=dpi)
  16.         self.axes = fig.add_subplot(111)
  17.  
  18.         self.plot_figure()
  19.  
  20.         FigureCanvas.__init__(self, fig)
  21.         self.setParent(parent)
  22.  
  23.         #FigureCanvas.setSizePolicy(self,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding)
  24.         #FigureCanvas.updateGeometry(self)
  25.  
  26.     def plot_figure(self):
  27.         pass
  28.  
  29.     def keyPressEvent(self,event):
  30.         if event.key() == Qt.Key_Right:
  31.             print("g")
  32.         else:
  33.             print("G")
  34.  
  35.  
  36. class MyStaticMplCanvas(MyCanvas):
  37.     def plot_figure(self):
  38.         x=np.arange(0,2*np.pi,0.1)
  39.         y=np.sin(x)
  40.         self.axes.plot(x,y,"-")
  41.         self.axes.set_xlabel("x")
  42.         self.axes.set_ylabel("y")
  43.         self.axes.set_xlim(0,2*np.pi)    
  44.  
  45.  
  46.  
  47. class Main(QDialog):
  48.     def __init__(self, parent=None):
  49.         super(Main, self).__init__(parent)
  50.  
  51.         canvas = MyStaticMplCanvas(self)
  52.  
  53.         layout = QVBoxLayout()
  54.         layout.addWidget(canvas)
  55.  
  56.         self.setLayout(layout)
  57.  
  58.         self.setWindowTitle('plot')
  59.         self.show()
  60.  
  61. if __name__ == '__main__':
  62.     app = QApplication(sys.argv)
  63.     win = Main()
  64.  
  65.     app.exec_()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top