「PyQtの基礎 - グラフ」の版間の差分

ナビゲーションに移動 検索に移動
編集の要約なし
編集の要約なし
34行目: 34行目:
  from PyQt5.QtCore import *
  from PyQt5.QtCore import *
  from PyQt5.QtWidgets import *
  from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon
   
   
  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
43行目: 42行目:
  class MainWindow(QMainWindow):
  class MainWindow(QMainWindow):
   
   
     def __init__(self):
     def __init__(self, parent=None):
        super().__init__()
      super(MainWindow, self).__init__(parent)
        self.left  = 10
      self.left  = 10
        self.top    = 10
      self.top    = 10
        self.title  = "PyQt5 matplotlib example - pythonspot.com"
      self.title  = "PyQt5 matplotlib example - pythonspot.com"
        self.width  = 640
      self.width  = 640
        self.height = 400
      self.height = 400
   
   
        self.setWindowTitle(self.title)
      self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
      self.setGeometry(self.left, self.top, self.width, self.height)
   
   
        m = PlotCanvas(self, width=5, height=4)
      m = PlotCanvas(self, width=5, height=4)
        m.move(0,0)
      m.move(0,0)
   
   
        button = QPushButton('PyQt5 button', self)
      button = QPushButton('PyQt5 button', self)
        button.setToolTip('This s an example button')
      button.setToolTip('This s an example button')
        button.move(500,0)
      button.move(500,0)
        button.resize(140,100)
      button.resize(140,100)
        self.show()
   
   
   
   
68行目: 65行目:
   
   
     def __init__(self, parent=None, width=5, height=4, dpi=100):
     def __init__(self, parent=None, width=5, height=4, dpi=100):
        fig      = Figure(figsize=(width, height), dpi=dpi)
      fig      = Figure(figsize=(width, height), dpi=dpi)
        self.axes = fig.add_subplot(111)
      self.axes = fig.add_subplot(111)
   
   
        FigureCanvas.__init__(self, fig)
      FigureCanvas.__init__(self, fig)
        self.setParent(parent)
      self.setParent(parent)
   
   
        FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
      FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)
      FigureCanvas.updateGeometry(self)
        self.plot()
      self.plot()
   
   
   
   
     def plot(self):
     def plot(self):
        data = [random.random() for i in range(25)]
      data = [random.random() for i in range(25)]
        ax  = self.figure.add_subplot(111)
      ax  = self.figure.add_subplot(111)
        ax.plot(data, 'r-')
      ax.plot(data, 'r-')
        ax.set_title("PyQt Matplotlib Example")
      ax.set_title("PyQt Matplotlib Example")
        self.draw()
      self.draw()
   
   
   
   
90行目: 87行目:
     app = QApplication(sys.argv)
     app = QApplication(sys.argv)
     window = MainWindow()
     window = MainWindow()
    window.show()
     sys.exit(app.exec_())
     sys.exit(app.exec_())
  </source>
  </source>
197行目: 195行目:
         self.w.setLayout(main_layout)
         self.w.setLayout(main_layout)
         self.setCentralWidget(self.w)
         self.setCentralWidget(self.w)
        self.show()
   
   
   
   
237行目: 234行目:
     app = QApplication(sys.argv)
     app = QApplication(sys.argv)
     window = plotGraph()
     window = plotGraph()
    window.show()
     sys.exit(app.exec_())
     sys.exit(app.exec_())
   
   

案内メニュー