2011-12-13 75 views
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) 

回答

2

我解決了這個使用setFixedSize的小部件,而不是讓佈局管理器來調整。我不明白爲什麼佈局經理想要收縮的小部件時,添加更多的情節,但問題仍然是固定的