7
我創建了一個簡單的python腳本,它在運行時應該在PyQT窗口中顯示嵌入式matplotlib圖形。我已經使用this教程來嵌入和運行圖形。除了命名約定和總體UI中的一些差異之外,我的圖形與上述教程中的完全相同。嵌入在PyQt中的Matplotlib交互式圖形
我的問題是,我想使這個交互式圖形,允許縮放和拖動,但我想只用鼠標(點擊和拖動,滾輪等),沒有工具欄(因爲我覺得它很醜)。
Widget類:
class MplCanvas(FigureCanvas):
"""
Creates a canvas on which to draw our widgets
"""
def __init__(self):
self.fig = Figure()
self.ax = self.fig.add_subplot(111)
FigureCanvas.__init__(self, self.fig)
FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
class marketdephWidget(QtGui.QWidget):
"""
The market deph graph
"""
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.canvas = MplCanvas()
self.vbl = QtGui.QVBoxLayout()
self.vbl.addWidget(self.canvas)
self.setLayout(self.vbl)
繪圖功能(按下按鈕運行):
# initialize the mplwidgets
def PlotFunc(self):
randomNumbers = random.sample(range(0, 10), 10)
self.ui.widget.canvas.ax.clear()
self.ui.widget.canvas.ax.plot(randomNumbers)
self.ui.widget.canvas.draw()