필자는 실행시 Python 창에 임베디드 matplotlib 그래프를 표시해야하는 간단한 파이썬 스크립트를 만들었습니다. 그래프를 임베딩하고 실행하기 위해 this 튜토리얼을 사용했습니다. 명명 규칙의 일부 차이점과 전반적인 UI에서 내 그래프는 앞서 언급 한 튜토리얼의 것과 동일하게 생성됩니다.PyQt에 임베디드 된 Matplotlib 대화 형 그래프
내 문제는이 확대/축소 및 끌기를 허용하는 대화 형 그래프를 만들고 싶습니다 있지만 마우스 (클릭 및 끌기, 스크롤 휠 등) 및 도구 모음없이이 작업을 수행하고 싶습니다. 내가보기에는 못생긴다.)
위젯 클래스 :
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()