3
我在PyQt4應用程序中嵌入了matplotlib圖。這是我基於Qt4嵌入示例在http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html製作的繪圖小部件。不幸的是,每次我添加一個新的圖,這個圖都會略微收縮。如果這樣做有所幫助,我會在QGridLayout
中並排排列兩個繪圖小部件。Matplotlib嵌入式PyQt4圖形在每次繪圖時調整大小
這種奇怪行爲的原因是什麼?
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
class MultiPlot(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
FigureCanvas.__init__(self, fig)
self.setParent(parent)
self.setMinimumSize(300, 200)
self.setMaximumSize(600, 400)
def plot(self,x,y):
print "Plot"
self.axes.plot(x,y)
FigureCanvas.updateGeometry(self)
def changePlot(self,plotNum,x,y):
print "Change plot",plotNum
self.axes.lines[plotNum].set_data(x,y)
FigureCanvas.updateGeometry(self)