gpt4 book ai didi

python - 将绘图嵌入 GUI 中

转载 作者:太空宇宙 更新时间:2023-11-03 16:14:29 25 4
gpt4 key购买 nike

我找到了一个网站 scikit-rf

http://scikit-rf.readthedocs.io/en/latest/tutorials/plotting.html

可以通过以下代码创建史密斯图

ntwk = rf.Network("my data path")
ntwk.plot_s_smith()

然后我想将它嵌入到我的 python gui 中。

import sys
from PyQt4 import QtGui,QtCore
import matplotlib
import matplotlib.figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
import skrf as rf
import numpy as np
class PrettyWidget(QtGui.QMainWindow):

def __init__(self):
super(PrettyWidget, self).__init__()
self.setGeometry(100,100,1200,700)
self.center()
self.setWindowTitle('NRW')



self.initUI()

def initUI(self):

grid = QtGui.QGridLayout()
self.setLayout(grid)
self.figure = matplotlib.figure.Figure()
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
grid.addWidget(self.canvas, 3,0,2,12)

def plot1(self):

self.figure.clf()
self.figure.tight_layout()
self.canvas.draw()



if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
app.aboutToQuit.connect(app.deleteLater)
GUI = PrettyWidget()
GUI.show()
app.exec_()

但我不知道如何放置或修改下面的代码

ntwk = rf.Network("my data path")
ntwk.plot_s_smith()

有人可以告诉我你是否有 iedas 吗?谢谢!

最佳答案

Network.plot_s_smith有一个 ax 关键字来在现有的 Axes 对象上绘制。所以你可以像这样修改你的绘图函数:

def plot1(self):

self.figure.clf()
ntwk = rf.Network("my data path")
ntwk.plot_s_smith(ax=self.figure.gca())
self.figure.tight_layout()
self.canvas.draw()

关于python - 将绘图嵌入 GUI 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39036462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com