我想在 Plot 类中创建的图形中绘制数据。
class DataWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
widget = QWidget()
layout = QVBoxLayout()
btn5 = QPushButton("plot")
btn5.clicked.connect(self.ctrl)
layout.addWidget(btn5, stretch=1)
def ctrl(self):
Plot().graph()
y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
x = [30, 32, 34, 32, 33, 31, 29, 32, 35, 45]
graphWidget.plot(x, y)
class Plot(QWidget):
def __init__(self):
QWidget.__init__(self)
self.layout = QVBoxLayout()
ly_widget = QWidget()
ly = QVBoxLayout()
self.graph()
ly.addWidget(self.graphWidget)
ly_widget.setLayout(ly)
self.layout.addWidget(ly_widget)
def graph(self):
self.graphWidget = pg.PlotWidget()
self.graphWidget.setBackground(QColor(330, 300, 270))
self.graphWidget.setXRange(0, 100)
self.graphWidget.setYRange(0, 10)
但是 graphWidget 在 DataWidget 类中不被识别。有人可以帮我吗?