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

<legend id='mNmTb'><style id='mNmTb'><dir id='mNmTb'><q id='mNmTb'></q></dir></style></legend>
    • <bdo id='mNmTb'></bdo><ul id='mNmTb'></ul>

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

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

        使用 pyqtgraph 和線程的實時繪圖

        Real-Time-Plotting using pyqtgraph and threading(使用 pyqtgraph 和線程的實時繪圖)
        • <bdo id='AgTFT'></bdo><ul id='AgTFT'></ul>

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

            <tbody id='AgTFT'></tbody>

                <legend id='AgTFT'><style id='AgTFT'><dir id='AgTFT'><q id='AgTFT'></q></dir></style></legend>
              1. <small id='AgTFT'></small><noframes id='AgTFT'>

              2. <tfoot id='AgTFT'></tfoot>
                  本文介紹了使用 pyqtgraph 和線程的實時繪圖的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  這有點長,第一部分只是對問題的描述,第二部分是我的修復"是否正確的問題.

                  this is a bit longer, the first part is just a description of the problem, the second one the question if my "fix" is correct.

                  我從 python 編程開始.我創建了一個程序,它與讀取我們熔化實驗室熔爐溫度的 Arduino 進行通信.然后在 PID 算法中使用溫度,并將輸出設置為 Arduino.通信是通過 pyserial 完成的.到目前為止,一切都有效,包括實時繪制溫度信號、PID 變量等.該腳本包括一個主循環和 3 個線程(串行通信、從串行端口讀取的數據移位器、來自 QWidget 的設定溫度和 PID 算法的輸出.這些值用于創建一個數組以在 pyqtgraph 中顯示.最后,第三個線程將數據從 datashifter 轉移到 QWidget.

                  I started with python programming. I created a program that communicates with an Arduino that reads the temperature of a furnace of our melting lab. The temperature is then used in a PID algorithm and an output is set to the Arduino. The communication is done via pyserial. So far, everthing works, including live plotting of the temperature signals, PID-variables and so on. The script includes a the main loop and 3 threads (serial communication, a datashifter that reads from serialport, the set temperature from the QWidget and the output of the PID algorithm. This values are used to create an array for displaying within pyqtgraph. Finally, the third thread shifts the data from the datashifter to the QWidget.

                  當使用我的 Linux 筆記本時,一切正常,并且 GUI 從未停止更新.相比之下,當使用任何 Windows 主機時,我會遇到一些 pyqtgraphs 停止刷新的問題.這種行為很奇怪,因為我或多或少地同時設置了所有數據,使用相同的 numpy 數組(只是不同的列)——有些圖刷新時間更長(小時),有些更早停止(分鐘).在搜索了或多或少的漏洞之后 ;-) 我認為我發現了問題:它是從線程到 GUI 的數據傳遞.一些虛擬代碼來解釋發生了什么:

                  When using my Linux-Notebook, everything works fine, and the GUI never stops updating. In contrast, when using any Windows-Host, i have the problem that some pyqtgraphs stop to refresh. The behavior is strange, because i set all data at more or less the same time, with the same numpy array (just different columns) - some plots refresh longer (hours), some stop earlier (minutes). After searching more or less the hole internet ;-) I think that I found the problem: Its the passing of data from from a thread to the GUI. Some dummy code to explain what's going on:

                  DataUpdaterToGUI(QThread):
                  
                  #sets the QWidget from main loop
                  def setGUI(self, gui):
                      self.gui = gui
                  
                  def run()
                      while True:
                          with lock(): # RLock() Instance
                             copyArray = self.dataArray[:] # copy the array from the shifter
                             self.gui.plot1.copyArray(dataArray[:, 0], copyArray[:, 1])
                             self.gui.plot2.copyArray(dataArray[:, 0], copyArray[:, 2])
                             # self.gui.update()
                             # QApplication.instance().processEvents() 
                  

                  調用 self.gui.update() 和 processEvents() 都不會對結果產生任何影響:繪圖會在一段時間后停止重繪(在 Windows 上).

                  Neither calling self.gui.update() nor processEvents() has any influence on the outcome: The plots stop redrawing after a while (on windows).

                  現在我有一個非常簡單的例子,只是想確定我是否正確使用了線程.它工作正常,但我有一些問題:

                  Now i have a very simple example, and just want to make sure if I'm using the threading-stuff correctly. It works fine, but I have some questions:

                  • 信號槽方法是否復制傳遞的數據?
                  • 為什么不需要調用QWidget的update()方法?
                  • 使用信號時是否必須使用任何類型的鎖?
                  class Main(QWidget):
                      def __init__(self):
                          super().__init__()
                  
                          self.layout = QGridLayout(self)
                          self.graph = pg.PlotWidget()
                          self.graph.setYRange(0,1000)
                          self.plot = self.graph.plot()
                          self.layout.addWidget(self.graph,0,0)
                          self.show()
                  
                      def make_connection(self, data_object):
                          data_object.signal.connect(self.grab_data)
                  
                      @pyqtSlot(object)
                      def grab_data(self, data):
                          print(data)
                          self.plot.setData(data)
                  
                  
                  class Worker(QThread):
                      signal = pyqtSignal(object)
                  
                      def __init__(self):
                          super().__init__()
                  
                      def run(self):
                          self.data = [0, 1]
                          i = 2
                          while True:
                              self.data[1] = i
                              self.signal.emit(self.data)
                              time.sleep(0.01)
                              i += 1
                  
                  if __name__ == "__main__": 
                      app = QApplication(sys.argv)
                  
                      widget = Main()
                      worker = Worker()
                      widget.make_connection(worker)
                      worker.start()
                  
                      sys.exit(app.exec_())
                  

                  推薦答案

                  信號槽方法是否復制傳遞的數據? 信號是線程安全的,并且在傳輸數據時會進行復制,所以數據之前的線程和消費它的線程(GUI線程)不會有沖突

                  Does the signal-slot approach copy the passed data? The signals are thread-safe and when transferring data they make a copy so the thread that precedes the data and the thread that consumes it (GUI Thread) will not have conflicts

                  為什么不需要調用QWidget的update()方法? 其實pyqtgraph調用的是update方法,plot是一個PlotDataItem,所以如果我們查看setData() 方法,它調用 updateItems() 方法,在該方法中的 setData() 方法曲線 或 scatter 屬性(根據圖形的類型),在曲線的情況 setData() 方法調用 updateData() 和 updateData() 方法調用更新,在分散的情況下,它的 setData() 方法調用 addpoint() 和 addPoints() 調用 invalidate(),而這個 invalidate() 方法調用 update().

                  Why is it not necessary to call the update() method of the QWidget? Actually pyqtgraph calls the update method, plot is a PlotDataItem, so if we check the source code of setData() method, it calls the updateItems() method, in that method the setData() method of the curve or scatter attribute is called (according to the type of graphics), in the case of curve its setData() method calls updateData(), and the updateData() method calls update, and in the case of the scatter its setData() method calls addpoint(), and addPoints() calls invalidate(), and this invalidate() method calls update().

                  在使用信號時我必須使用任何類型的鎖嗎?不需要,因為信號是線程安全的,所以 Qt 已經設置了保護以避免沖突.

                  Do I have to use any kind of locks when using signals? No, as the signals are thread-safe so Qt already has the guards set to avoid the collision.

                  這篇關于使用 pyqtgraph 和線程的實時繪圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 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 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)

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

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

                          <tfoot id='JxRDw'></tfoot>
                            主站蜘蛛池模板: 99国产视频| 亚洲日日夜夜 | 一区二区三区在线播放 | 日韩欧美一区二区三区在线播放 | 99精品视频免费观看 | 成人在线播放网址 | 影音先锋欧美资源 | 欧美精品一区二区三区四区五区 | 欧美猛交 | 欧美一区二区黄 | 久久草在线视频 | 国产精品成人在线 | 日韩中文字幕在线播放 | 美女视频三区 | 国产精品久久久久久婷婷天堂 | 久久国产精品-国产精品 | 1区2区视频 | 亚洲成人三级 | 国产精品一码二码三码在线 | 99re国产 | 视频一区二区在线观看 | 久久丝袜| 欧美一级黄视频 | 亚洲一区二区三区在线观看免费 | 国产午夜久久 | 欧美一区二区三区在线看 | 欧美久久电影 | 国产福利91精品一区二区三区 | 成人国产精品色哟哟 | 日本不卡在线视频 | 国产 欧美 日韩 一区 | 亚洲精品视频免费 | 激情av | av在线二区 | av片在线免费看 | 九九精品在线 | 亚洲欧美在线观看 | 国产ts人妖一区二区三区 | 精区3d动漫一品二品精区 | 综合久久久| 日本黄色免费片 |