首页 > 解决方案 > 在 Python 上绘制史密斯图

问题描述

我正在尝试使用 matplotlib 和 scikit-rf 在 python 中绘制史密斯图,

我已经在图中绘制了史密斯图,但我需要能够在程序中绘制它以将其可视化为图形。按照我找到的示例,我有一个问题,当我想绘制它时,它的格式不是x,y。

我能做些什么才能画出来?

 from PyQt5.QtWidgets import*

 from matplotlib.backends.backend_qt5agg import FigureCanvas

 from matplotlib.figure import Figure

类 SmithPrueba_graphicsView(QWidget):

    def __init__(self, parent = None):

        QWidget.__init__(self, parent)
        
        self.canvas = FigureCanvas(Figure())
        
        vertical_layout = QVBoxLayout()
        vertical_layout.addWidget(self.canvas)
        
        # vertical_layout = QVBoxLayout()
        # vertical_layout.addWidget(self.canvas)
        
        
        #self.canvas.axes = self.canvas.figure.add_subplot(111)
        self.canvas.axes = self.canvas.figure.add_subplot(111)
        self.setLayout(vertical_layout)


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import*
from PyQt5.uic import loadUi
from matplotlib.backends.backend_qt5agg import (NavigationToolbar2QT as NavigationToolbar)
import PruebaCartaSmith
import numpy as np
import random


import skrf as rf

from skrf.data import ring_slot
from skrf import Network
from skrf import Frequency
import matplotlib.pyplot as plt
import os
     
class PruebaSmithChart(PruebaCartaSmith.QtWidgets.QMainWindow,PruebaCartaSmith.Ui_MainWindow):
    
    # def __init__(self, parent,design2open):
    #     super(MatplotlibWidget, self).__init__()
    
    def __init__(self):
        
        QMainWindow.__init__(self)
        
        self.setupUi(self)

        self.setWindowTitle("PyQt5 & Matplotlib Example GUI")
        

        self.pushButton_generate_random_signal.clicked.connect(self.update_graph)

        self.addToolBar(NavigationToolbar(self.SmithPrueba_graphicsView.canvas, self))

        def update_graph(self):
            prueba=Network('UserProjects/proyecto3_pro/Datasets/pruebasmithdataset.s2p')
            self.SmithPrueba_graphicsView.canvas.axes.clear()
            self.SmithPrueba_graphicsView.canvas.axes.plot(prueba.plot_s_smith())
            self.SmithPrueba_graphicsView.canvas.axes.set_title('Cosinus - Sinus Signal')
            self.SmithPrueba_graphicsView.canvas.draw()

app = PruebaCartaSmith.QtWidgets.QApplication([])
# MainWindow=Ui_MainWindow()
window = PruebaSmithChart()
window.show()
app.exec_()

绘图错误

主程序

标签: pythonmatplotlib

解决方案


推荐阅读