久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='IigSP'><tr id='IigSP'><dt id='IigSP'><q id='IigSP'><span id='IigSP'><b id='IigSP'><form id='IigSP'><ins id='IigSP'></ins><ul id='IigSP'></ul><sub id='IigSP'></sub></form><legend id='IigSP'></legend><bdo id='IigSP'><pre id='IigSP'><center id='IigSP'></center></pre></bdo></b><th id='IigSP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IigSP'><tfoot id='IigSP'></tfoot><dl id='IigSP'><fieldset id='IigSP'></fieldset></dl></div>
<legend id='IigSP'><style id='IigSP'><dir id='IigSP'><q id='IigSP'></q></dir></style></legend>

      • <bdo id='IigSP'></bdo><ul id='IigSP'></ul>

      <small id='IigSP'></small><noframes id='IigSP'>

    1. <tfoot id='IigSP'></tfoot>

      1. 如何使用 python 同時運(yùn)行 matplotlib 和 PyQt5 Video

        How can run both of matplotlib and PyQt5 Video with python(如何使用 python 同時運(yùn)行 matplotlib 和 PyQt5 Video)

        <i id='d0P0f'><tr id='d0P0f'><dt id='d0P0f'><q id='d0P0f'><span id='d0P0f'><b id='d0P0f'><form id='d0P0f'><ins id='d0P0f'></ins><ul id='d0P0f'></ul><sub id='d0P0f'></sub></form><legend id='d0P0f'></legend><bdo id='d0P0f'><pre id='d0P0f'><center id='d0P0f'></center></pre></bdo></b><th id='d0P0f'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='d0P0f'><tfoot id='d0P0f'></tfoot><dl id='d0P0f'><fieldset id='d0P0f'></fieldset></dl></div>
          <tbody id='d0P0f'></tbody>

          <bdo id='d0P0f'></bdo><ul id='d0P0f'></ul>
          • <tfoot id='d0P0f'></tfoot>

            1. <legend id='d0P0f'><style id='d0P0f'><dir id='d0P0f'><q id='d0P0f'></q></dir></style></legend>

              <small id='d0P0f'></small><noframes id='d0P0f'>

                • 本文介紹了如何使用 python 同時運(yùn)行 matplotlib 和 PyQt5 Video的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在嘗試同時運(yùn)行 QVideoWidget 和 matplotlib 動畫,

                  I'm trying to run QVideoWidget and matplotlib animation together,

                  但是當(dāng)我運(yùn)行這個 py 時,QVideoWidget 不起作用.

                  but when I run this py, QVideoWidget is not working.

                  我得到了 QVideoWidget 代碼和 matplotlib 動畫代碼,然后將這些代碼匯總到下面的代碼中.

                  I got QVideoWidget code and matplotlib animation code then sum those code together in below code.

                  如果我關(guān)閉 matplotlib 動畫窗口,則 QVideoWidget 正在工作.

                  If I close the matplotlib animation Window, then the QVideoWidget is working.

                  我想知道為什么會發(fā)生這種情況并解決這個問題

                  I wonder why this happen and solve this problem

                  謝謝

                  import matplotlib.pyplot as plt
                  import matplotlib.animation as animation
                  import random
                  from PyQt5.QtCore import QDir, Qt, QUrl
                  from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
                  from PyQt5.QtMultimediaWidgets import QVideoWidget
                  from PyQt5.QtWidgets import (QApplication, QFileDialog, QHBoxLayout, QLabel,
                      QPushButton, QSizePolicy, QSlider, QStyle, QVBoxLayout, QWidget)
                  from PyQt5.QtWidgets import QMainWindow,QWidget, QPushButton, QAction
                  from PyQt5.QtGui import QIcon
                  import sys
                  from PyQt5.QtWidgets import (QApplication, QCheckBox, QGridLayout, QGroupBox,
                      QMenu, QPushButton, QRadioButton, QVBoxLayout, QWidget)
                  
                  # Parameters
                  x_len = 200         # Number of points to display
                  y_range = [10, 40]  # Range of possible Y values to display
                  
                  # Create figure for plotting
                  fig = plt.figure(facecolor='white')
                  ax = fig.add_subplot(2, 1, 1)
                  bx = fig.add_subplot(2, 1, 2)
                  xs = list(range(0, 200))
                  ys = [0] * x_len
                  ax.set_ylim(y_range)
                  bx.set_ylim(y_range)
                  # Initialize communication with TMP102
                  
                  
                  # When everything done, release the capture
                  
                  
                  # Create a blank line. We will update the line in animate
                  line, = ax.plot(xs, ys)
                  line2, = bx.plot(xs, ys)
                  # Add labels
                  plt.title('TMP102 Temperature over Time')
                  plt.xlabel('Samples')
                  plt.ylabel('Temperature (deg C)')
                  class VideoWindow(QMainWindow):
                      def __init__(self, parent=None):
                  
                          super(VideoWindow, self).__init__(parent)
                  
                          self.setWindowTitle("PyQt Video Player Widget Example - pythonprogramminglanguage.com")
                  
                          self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)
                  
                          videoWidget = QVideoWidget()
                  
                          self.playButton = QPushButton()
                          self.playButton.setEnabled(False)
                          self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
                          self.playButton.clicked.connect(self.play)
                  
                          self.positionSlider = QSlider(Qt.Horizontal)
                          self.positionSlider.setRange(0, 0)
                          self.positionSlider.sliderMoved.connect(self.setPosition)
                  
                          self.errorLabel = QLabel()
                          self.errorLabel.setSizePolicy(QSizePolicy.Preferred,
                              QSizePolicy.Maximum)
                  
                          # Create new action
                          openAction = QAction(QIcon('open.png'), '&Open', self)
                          openAction.setShortcut('Ctrl+O')
                          openAction.setStatusTip('Open movie')
                          openAction.triggered.connect(self.openFile)
                  
                          # Create exit action
                          exitAction = QAction(QIcon('exit.png'), '&Exit', self)
                          exitAction.setShortcut('Ctrl+Q')
                          exitAction.setStatusTip('Exit application')
                          exitAction.triggered.connect(self.exitCall)
                  
                          # Create menu bar and add action
                          menuBar = self.menuBar()
                          fileMenu = menuBar.addMenu('&File')
                          #fileMenu.addAction(newAction)
                          fileMenu.addAction(openAction)
                          fileMenu.addAction(exitAction)
                  
                          # Create a widget for window contents
                          wid = QWidget(self)
                          self.setCentralWidget(wid)
                  
                          # Create layouts to place inside widget
                          controlLayout = QHBoxLayout()
                          controlLayout.setContentsMargins(0, 0, 0, 0)
                          controlLayout.addWidget(self.playButton)
                          controlLayout.addWidget(self.positionSlider)
                          layout = QVBoxLayout()
                          layout.addWidget(videoWidget)
                          layout.addLayout(controlLayout)
                          layout.addWidget(self.errorLabel)
                          # Set widget to contain window contents
                  
                          wid.setLayout(layout)
                  
                          self.mediaPlayer.setVideoOutput(videoWidget)
                          self.mediaPlayer.stateChanged.connect(self.mediaStateChanged)
                          self.mediaPlayer.positionChanged.connect(self.positionChanged)
                          self.mediaPlayer.durationChanged.connect(self.durationChanged)
                          self.mediaPlayer.error.connect(self.handleError)
                  
                  
                      def openFile(self):
                          fileName, _ = QFileDialog.getOpenFileName(self, "Open Movie",
                              QDir.homePath())
                  
                          if fileName != '':
                              self.mediaPlayer.setMedia(
                                  QMediaContent(QUrl.fromLocalFile(fileName)))
                              self.playButton.setEnabled(True)
                  
                      def exitCall(self):
                          sys.exit(app.exec_())
                  
                      def play(self):
                          if self.mediaPlayer.state() == QMediaPlayer.PlayingState:
                              self.mediaPlayer.pause()
                          else:
                              self.mediaPlayer.play()
                  
                      def mediaStateChanged(self, state):
                          if self.mediaPlayer.state() == QMediaPlayer.PlayingState:
                              self.playButton.setIcon(
                                  self.style().standardIcon(QStyle.SP_MediaPause))
                          else:
                              self.playButton.setIcon(
                                  self.style().standardIcon(QStyle.SP_MediaPlay))
                  
                      def positionChanged(self, position):
                          self.positionSlider.setValue(position)
                  
                      def durationChanged(self, duration):
                          self.positionSlider.setRange(0, duration)
                  
                      def setPosition(self, position):
                          self.mediaPlayer.setPosition(position)
                  
                  
                  
                      def handleError(self):
                          self.playButton.setEnabled(False)
                          self.errorLabel.setText("Error: " + self.mediaPlayer.errorString())
                  
                      def animate(i, ys):
                  
                          # Read temperature (Celsius) from TMP102
                          temp_c = random.randint(15, 35)
                  
                          # Add y to list
                          ys.append(temp_c)
                  
                          # Limit y list to set number of items
                          ys = ys[-x_len:]
                  
                          # Update line with new Y values
                          line.set_ydata(ys)
                          line2.set_ydata(ys)
                          return line, line2,
                  
                      ani = animation.FuncAnimation(fig, animate, fargs=(ys,),
                                                interval=50,
                                                blit=True)
                  
                  # This function is called periodically from FuncAnimation
                  
                  
                  # Set up plot to call animate() function periodically
                  
                  
                  
                  if __name__ == '__main__':
                      app = QApplication(sys.argv)
                  
                      player = VideoWindow()
                      player.resize(640, 480)
                      player.show()
                      plt.show()
                      sys.exit(app.exec_())
                  

                  推薦答案

                  每個 GUI 都需要一個事件循環(huán)來更新自身并參與用戶事件、操作系統(tǒng)事件等.對于 matplotlib,它在使用時被調(diào)用plt.show() 以及調(diào)用 app.exec_() 時的 PyQt5.使用您當(dāng)前的代碼,matplotlib 的事件循環(huán)正在阻塞 PyQt,因此您無法與 PyQt5 創(chuàng)建的窗口進(jìn)行交互.

                  Every GUI needs an event loop to be able to update itself and attend user events, OS events, etc. And in the case of matplotlib it is called when using plt.show() and in the case of PyQt5 when calling app.exec_(). With your current code the event loop of matplotlib is blocking PyQt, so you can not interact with the window created by PyQt5.

                  解決方法很簡單,matplotlib支持包括PyQt5在內(nèi)的多個后端,所以解決方法就是使用它,在下面鏈接你可以找到一個例子.

                  The solution is simple, matplotlib supports several backends including PyQt5, so the solution is to use it, in the following link you can find an example.

                  綜合考慮,下面的代碼實(shí)現(xiàn)了解決方案:

                  Considering the above, the following code implements the solution:

                  import random
                  import matplotlib
                  # Make sure that we are using QT5
                  matplotlib.use('Qt5Agg')
                  from PyQt5 import QtCore, QtGui, QtWidgets, QtMultimedia, QtMultimediaWidgets
                  
                  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
                  from matplotlib.figure import Figure
                  import matplotlib.animation as animation
                  
                  
                  class MyMplCanvas(FigureCanvas):
                      def __init__(self, parent=None, width=5, height=4, dpi=100):
                          fig = Figure(figsize=(width, height), dpi=dpi)
                  
                          # https://stackoverflow.com/a/6981055/6622587
                          ax = fig.add_subplot(111)    # The big subplot
                          self.ax = fig.add_subplot(211)
                          self.bx = fig.add_subplot(212)
                  
                          FigureCanvas.__init__(self, fig)
                          self.setParent(parent)
                  
                          FigureCanvas.setSizePolicy(self,
                                                     QtWidgets.QSizePolicy.Expanding,
                                                     QtWidgets.QSizePolicy.Expanding)
                          FigureCanvas.updateGeometry(self)
                  
                          ax.set_title('TMP102 Temperature over Time')
                          ax.spines['top'].set_color('none')
                          ax.spines['bottom'].set_color('none')
                          ax.spines['left'].set_color('none')
                          ax.spines['right'].set_color('none')
                          ax.tick_params(labelcolor='w', top=False, bottom=False, left=False, right=False)
                          ax.set_xlabel('Samples')
                          ax.set_ylabel('Temperature (deg C)')
                  
                          self.x_len = 200         # Number of points to display
                          self.y_range = [10, 40]  # Range of possible Y values to display
                          self.xs = list(range(0, 200))
                  
                          self.ys = [0 for _ in range(self.x_len)]        
                          self.anim = animation.FuncAnimation(fig, self.animate, init_func=self.init, interval=50,blit=True)
                  
                      def init(self):
                          y_range = [10, 40]
                          self.ax.set_ylim(*y_range)
                          self.bx.set_ylim(*y_range)
                          self.line, = self.ax.plot(self.xs, self.ys)
                          self.line2, = self.bx.plot(self.xs, self.ys)
                          return self.line, self.line2
                  
                      def animate(self, i):
                          temp_c = random.randint(15, 35)
                          self.ys.append(temp_c)
                          self.ys = self.ys[-self.x_len:]
                          self.line.set_ydata(self.ys)
                          self.line2.set_ydata(self.ys)
                          return self.line, self.line2
                  
                  
                  class ApplicationWindow(QtWidgets.QMainWindow):
                      def __init__(self, parent=None):
                          super(ApplicationWindow, self).__init__(parent)
                          main_widget = QtWidgets.QWidget()
                          l = QtWidgets.QVBoxLayout(main_widget)
                          sc = MyMplCanvas(main_widget, width=5, height=4, dpi=100)
                          l.addWidget(sc)
                          self.setCentralWidget(main_widget)
                  
                  
                  class VideoWindow(QtWidgets.QMainWindow):
                      def __init__(self, parent=None):
                  
                          super(VideoWindow, self).__init__(parent)
                  
                          self.setWindowTitle("PyQt Video Player Widget Example - pythonprogramminglanguage.com")
                  
                          self.mediaPlayer = QtMultimedia.QMediaPlayer(self, QtMultimedia.QMediaPlayer.VideoSurface)
                  
                          videoWidget = QtMultimediaWidgets.QVideoWidget()
                  
                          self.playButton = QtWidgets.QPushButton()
                          self.playButton.setEnabled(False)
                          self.playButton.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPlay))
                          self.playButton.clicked.connect(self.play)
                  
                          self.positionSlider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
                          self.positionSlider.setRange(0, 0)
                          self.positionSlider.sliderMoved.connect(self.setPosition)
                  
                          self.errorLabel =QtWidgets.QLabel()
                          self.errorLabel.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum)
                  
                          # Create new action
                          openAction = QtWidgets.QAction(QtGui.QIcon('open.png'), '&Open', self)
                          openAction.setShortcut('Ctrl+O')
                          openAction.setStatusTip('Open movie')
                          openAction.triggered.connect(self.openFile)
                  
                          # Create exit action
                          exitAction = QtWidgets.QAction(QtGui.QIcon('exit.png'), '&Exit', self)
                          exitAction.setShortcut('Ctrl+Q')
                          exitAction.setStatusTip('Exit application')
                          exitAction.triggered.connect(self.exitCall)
                  
                          # Create menu bar and add action
                          menuBar = self.menuBar()
                          fileMenu = menuBar.addMenu('&File')
                          #fileMenu.addAction(newAction)
                          fileMenu.addAction(openAction)
                          fileMenu.addAction(exitAction)
                  
                          # Create a widget for window contents
                          wid = QtWidgets.QWidget()
                          self.setCentralWidget(wid)
                  
                          # Create layouts to place inside widget
                          controlLayout = QtWidgets.QHBoxLayout()
                          controlLayout.setContentsMargins(0, 0, 0, 0)
                          controlLayout.addWidget(self.playButton)
                          controlLayout.addWidget(self.positionSlider)
                          layout = QtWidgets.QVBoxLayout()
                          layout.addWidget(videoWidget)
                          layout.addLayout(controlLayout)
                          layout.addWidget(self.errorLabel)
                          # Set widget to contain window contents
                  
                          wid.setLayout(layout)
                  
                          self.mediaPlayer.setVideoOutput(videoWidget)
                          self.mediaPlayer.stateChanged.connect(self.mediaStateChanged)
                          self.mediaPlayer.positionChanged.connect(self.positionChanged)
                          self.mediaPlayer.durationChanged.connect(self.durationChanged)
                          self.mediaPlayer.error.connect(self.handleError)
                  
                  
                      def openFile(self):
                          fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Open Movie", QtCore.QDir.homePath())
                  
                          if fileName:
                              media = QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile(fileName))
                              self.mediaPlayer.setMedia(media)
                              self.playButton.setEnabled(True)
                  
                      def exitCall(self):
                          QtWidgets.QApplication.quit()
                  
                      def play(self):
                          if self.mediaPlayer.state() == QtMultimedia.QMediaPlayer.PlayingState:
                              self.mediaPlayer.pause()
                          else:
                              self.mediaPlayer.play()
                  
                      def mediaStateChanged(self, state):
                          if self.mediaPlayer.state() == QtMultimedia.QMediaPlayer.PlayingState:
                              self.playButton.setIcon(
                                  self.style().standardIcon(QtWidgets.QStyle.SP_MediaPause))
                          else:
                              self.playButton.setIcon(
                                  self.style().standardIcon(QtWidgets.QStyle.SP_MediaPlay))
                  
                      def positionChanged(self, position):
                          self.positionSlider.setValue(position)
                  
                      def durationChanged(self, duration):
                          self.positionSlider.setRange(0, duration)
                  
                      def setPosition(self, position):
                          self.mediaPlayer.setPosition(position)
                  
                      def handleError(self):
                          self.playButton.setEnabled(False)
                          self.errorLabel.setText("Error: " + self.mediaPlayer.errorString())
                  
                  
                  if __name__ == '__main__':
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                  
                      player = VideoWindow()
                      player.resize(640, 480)
                      player.show()
                  
                      w = ApplicationWindow()
                      w.show()
                      sys.exit(app.exec_())
                  

                  這篇關(guān)于如何使用 python 同時運(yùn)行 matplotlib 和 PyQt5 Video的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進(jìn)度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動時,yaxis 刻度標(biāo)簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進(jìn)度條?)
                • <small id='tYYCP'></small><noframes id='tYYCP'>

                  <legend id='tYYCP'><style id='tYYCP'><dir id='tYYCP'><q id='tYYCP'></q></dir></style></legend>

                        <i id='tYYCP'><tr id='tYYCP'><dt id='tYYCP'><q id='tYYCP'><span id='tYYCP'><b id='tYYCP'><form id='tYYCP'><ins id='tYYCP'></ins><ul id='tYYCP'></ul><sub id='tYYCP'></sub></form><legend id='tYYCP'></legend><bdo id='tYYCP'><pre id='tYYCP'><center id='tYYCP'></center></pre></bdo></b><th id='tYYCP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='tYYCP'><tfoot id='tYYCP'></tfoot><dl id='tYYCP'><fieldset id='tYYCP'></fieldset></dl></div>
                        • <bdo id='tYYCP'></bdo><ul id='tYYCP'></ul>
                          <tfoot id='tYYCP'></tfoot>
                              <tbody id='tYYCP'></tbody>
                          1. 主站蜘蛛池模板: 青青久久| 久久久久久99 | 91综合在线观看 | 在线国产视频 | 日韩国产一区二区三区 | 午夜精品一区二区三区免费视频 | 亚洲国产欧美一区 | 成人黄色电影免费 | 亚洲成人99 | 这里只有精品99re | 欧美一级特黄aaa大片在线观看 | 欧美国产精品一区二区三区 | 日韩超碰在线 | 一本色道精品久久一区二区三区 | 精品国产精品国产偷麻豆 | 久久久久成人精品亚洲国产 | 色婷婷久久久亚洲一区二区三区 | 日本黄色高清视频 | 99在线视频观看 | 国产精品视频 | 日韩在线观看视频一区 | 草草草影院 | 国产一区二区三区亚洲 | 9久9久9久女女女九九九一九 | 涩涩视频在线看 | 天堂一区二区三区四区 | 欧美精品在线免费观看 | 久久精品av麻豆的观看方式 | 成人av观看 | www.av在线| 区一区二区三在线观看 | 日韩免费1区二区电影 | 台湾佬伊人 | 欧美一区二区三区在线免费观看 | 欧美日韩专区 | 欧美一区二区在线视频 | 99re热精品视频 | 欧美日韩高清 | 欧美日韩三级 | 日韩视频免费看 | av中文字幕在线播放 |