我在PyQt4应用程序中嵌入了一个matplotlib图形。这是基于Qt4嵌入示例制作的绘图小部件,样例网址:http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html。不幸的是,每次添加新图时,这个图表会略微缩小。如果我把两个绘图小部件并排放置在
QGridLayout
中,是否会有所不同呢?造成这种奇怪行为的原因是什么?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)