我在与我通过 Qt Designer 创建的 MatplotlibWidget 交互时遇到问题。我无法更改坐标轴标签、比例、提供标题或任何内容。我做错什么了吗?
这是使用 Qt Designer 生成的示例 UI 代码:
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.mplwidget = MatplotlibWidget(self.centralwidget)
self.mplwidget.setGeometry(QtCore.QRect(70, 50, 400, 300))
self.mplwidget.setObjectName("mplwidget")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
from matplotlibwidget import MatplotlibWidget
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None, f=QtCore.Qt.WindowFlags()):
QtGui.QMainWindow.__init__(self, parent, f)
self.setupUi(self)
这是我为与 UI python 代码交互而编写的 python 代码:
from PyQt4 import QtGui, QtCore
from TestUI2 import MainWindow
class Window(MainWindow):
def __init__(self):
MainWindow.__init__(self)
x=[0,10,100]
y=[3,4,5]
self.mplwidget.axes.set_xscale('log') # Nothing Happens
self.mplwidget.axes.set_title('GRAPH') # Nothing Happens
self.mplwidget.axes.plot(x,y)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())