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

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

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

      <small id='81AUh'></small><noframes id='81AUh'>

        <bdo id='81AUh'></bdo><ul id='81AUh'></ul>
      1. 顯示來自其他文件的 Matplotlib 圖

        Display Matplotlib plots from Other File(顯示來自其他文件的 Matplotlib 圖)

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

          <tbody id='Fawc3'></tbody>

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

            • <legend id='Fawc3'><style id='Fawc3'><dir id='Fawc3'><q id='Fawc3'></q></dir></style></legend>

                1. <tfoot id='Fawc3'></tfoot>
                  本文介紹了顯示來自其他文件的 Matplotlib 圖的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一個(gè) PyQt 文件,只需單擊一個(gè)按鈕,它就會(huì)運(yùn)行另一個(gè) python 文件(我們稱之為 calc.py)中的函數(shù),該文件執(zhí)行非常高級(jí)的計(jì)算并使用 matplotlib 進(jìn)行繪圖結(jié)果.

                  I have a PyQt file that, on the click of a button, runs a function from another python file (let's call calc.py) that carries out a really advanced calculation and uses matplotlib to plot the result.

                  我想在計(jì)算完成/生成圖形后,在 PyQt 窗口中顯示 calc.py 生成的這個(gè)圖.不過,鑒于計(jì)算和數(shù)字是在另一個(gè)文件中進(jìn)行的,我不確定執(zhí)行此操作的最佳方法.

                  I would like to show this plot generated by calc.py in the PyQt window after the calculation is complete/the figure is generated. Although, I'm not sure the best way to carry this out given that the calculation and figure are made in another file.

                  pyqt.py

                  import PyQt5 . . .
                  from calc import do_calc
                  
                  class Window(QMainWindow):
                      def __init__(self, parent=None):
                          super(Window, self).__init__(parent)
                          self.title_label = QLabel("Label Text", self)  #random label in top of window
                              
                          ###code here to display matplotlib plot in my PyQt app####
                  
                  if __name__ == '__main__':
                      app = QApplication(sys.argv)
                      window = Window()
                      window.show()
                      sys.exit(app.exec_())
                  

                  calc.py

                  import matplotlib.pyplot as plt
                   
                  def do_calc():
                     plt.figure()
                     for i in x: 
                        ...        #really complex calculation here
                        plt.plot()
                  
                     plt.draw()
                  

                  我一直在查看如何在 Qt 中顯示 matplotlib 圖的其他示例,但它們通常圍繞在 PyQt 文件或小部件類中進(jìn)行的計(jì)算,在這種情況下我無法真正做到.我可以更改 calc.py 文件以返回項(xiàng)目或執(zhí)行任何其他可能有用的操作,但計(jì)算可能需要保留在該文件中,以便它可以獨(dú)立于 PyQt 運(yùn)行

                  I've been looking at other examples of how to display matplotlib plots in Qt but they usually orient around the calculation being done in the PyQt file or widget class which I can't really do in this instance. I can alter the calc.py file to return items or do anything else that might be helpful, but the calculations will likely need to stay in that file so it can be ran independently from the PyQt

                  推薦答案

                  解決方案是一個(gè)hack(將來可能會(huì)失敗)假設(shè)calc.py中matplotlib使用的后端使用PyQt5,為此需要先導(dǎo)入 PyQt5,再導(dǎo)入 calc.py.

                  The solution is a hack(may fail in the future) that assumes that the backend used by matplotlib in calc.py uses PyQt5, for this it is necessary to import PyQt5 first and then calc.py.

                  邏輯是使用plt.ion使matplotlib不阻塞eventloop,然后在以FigureCanvas作為centralWidget的頂層(窗口)中搜索.

                  The logic is to make matplotlib not block the eventloop using plt.ion, and then search among the toplevels (windows) that have a FigureCanvas as their centralWidget.

                  calc.py

                  import matplotlib.pyplot as plt
                  import numpy as np
                  
                  
                  def do_calc():
                      t = np.arange(0.0, 2.0, 0.01)
                      s = 1 + np.sin(2 * np.pi * t)
                  
                      fig, ax = plt.subplots()
                      ax.plot(t, s)
                  
                      ax.set(
                          xlabel="time (s)",
                          ylabel="voltage (mV)",
                          title="About as simple as it gets, folks",
                      )
                      ax.grid()
                      plt.show()
                  

                  ma??in.py

                  import sys
                  
                  from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QVBoxLayout, QWidget
                  
                  import matplotlib.pyplot as plt
                  from matplotlib.backends.backend_qt5agg import FigureCanvas
                  
                  from calc import do_calc
                  
                  
                  
                  class Window(QMainWindow):
                      def __init__(self, parent=None):
                          super(Window, self).__init__(parent)
                  
                          self.title_label = QLabel("Label Text")
                  
                          central_widget = QWidget()
                          self.setCentralWidget(central_widget)
                          lay = QVBoxLayout(central_widget)
                          lay.addWidget(self.title_label)
                  
                          plt.ion()
                          do_calc()
                  
                          for tl in QApplication.topLevelWidgets():
                              if isinstance(tl, QMainWindow) and isinstance(
                                  tl.centralWidget(), FigureCanvas
                              ):
                                  lay.addWidget(tl)
                  
                  
                  if __name__ == "__main__":
                      app = QApplication(sys.argv)
                      window = Window()
                      window.show()
                      sys.exit(app.exec_())
                  

                  另一個(gè)更好的選擇是獲取所有圖形,然后是畫布,最后是該畫布的窗口:

                  Another better option is to get all the Figures and then the canvas and finally the window of that canvas:

                  class Window(QMainWindow):
                      def __init__(self, parent=None):
                          super(Window, self).__init__(parent)
                  
                          self.title_label = QLabel("Label Text")
                  
                          central_widget = QWidget()
                          self.setCentralWidget(central_widget)
                          lay = QVBoxLayout(central_widget)
                          lay.addWidget(self.title_label)
                  
                          plt.ion()
                          do_calc()
                  
                          for i in plt.get_fignums():
                              canvas = plt.figure(i).canvas
                              if isinstance(canvas, QWidget):
                                  lay.addWidget(canvas.window())
                  

                  這篇關(guān)于顯示來自其他文件的 Matplotlib 圖的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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 啟動(dòng)后進(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)我向左或向右滾動(dòng)時(shí),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時(shí)顯示進(jìn)度條?)

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

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

                          <tbody id='d8BdB'></tbody>
                        • <bdo id='d8BdB'></bdo><ul id='d8BdB'></ul>

                          <i id='d8BdB'><tr id='d8BdB'><dt id='d8BdB'><q id='d8BdB'><span id='d8BdB'><b id='d8BdB'><form id='d8BdB'><ins id='d8BdB'></ins><ul id='d8BdB'></ul><sub id='d8BdB'></sub></form><legend id='d8BdB'></legend><bdo id='d8BdB'><pre id='d8BdB'><center id='d8BdB'></center></pre></bdo></b><th id='d8BdB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='d8BdB'><tfoot id='d8BdB'></tfoot><dl id='d8BdB'><fieldset id='d8BdB'></fieldset></dl></div>
                        • <tfoot id='d8BdB'></tfoot>
                          • 主站蜘蛛池模板: 欧美一区成人 | 欧美日韩三级 | 免费在线观看成人 | 亚洲精品一区二 | 久久国产精品久久国产精品 | 欧美中文一区 | 日本精品视频在线观看 | 国产精品久久久久久久久久三级 | 蜜桃视频在线观看www社区 | 精品一区二区三区中文字幕 | 欧美一级小视频 | 美女啪啪国产 | 国产在线小视频 | 91在线免费观看 | 白浆在线 | 欧美日韩在线观看一区 | h视频在线播放 | 丁香五月缴情综合网 | 日韩一区二区三区在线视频 | 欧美日韩网站 | 国产精品夜夜春夜夜爽久久电影 | 999视频 | 色综合中文 | 亚洲天堂中文字幕 | 干狠狠 | 韩国av网站在线观看 | cao视频 | 91欧美| 国产一区二区三区视频 | 91在线视频免费观看 | 欧美精品一区二区三区在线播放 | 日韩精品一区二区三区在线 | 欧美福利视频 | 国户精品久久久久久久久久久不卡 | www.婷婷 | 特级黄一级播放 | 天天色天天色 | 一级毛毛片| 久久综合久久久 | 欧美激情国产精品 | 一级黄色毛片免费 |