Matplotlib嵌入PyQt4绘图时每次调用时图形大小都会改变

3
我在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)
1个回答

2
我使用 setFixedSize 在小部件上而不是允许布局管理器调整大小来解决了这个问题。我不明白为什么布局管理器会在添加更多的图时想要 缩小 小部件,但问题已经得到解决了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接