On Sun, Apr 18, 2010 at 12:55 PM, Gökhan Sever <gokhanse...@gmail.com> wrote: > > > On Sun, Apr 18, 2010 at 11:47 AM, Darren Dale <dsdal...@gmail.com> wrote: >> >> On Tue, Apr 13, 2010 at 8:14 PM, Gökhan Sever <gokhanse...@gmail.com> >> wrote: >> > Hello, >> > >> > Could someone confirm me if there is any malfunctioning using these >> > simple >> > figure functions? >> > >> > plt.figure(figsize=(2,3)) >> > >> > plt.figure(figsize=(5,6)) >> > >> > plt.figure(figsize=(9,15)) >> > >> > plt.figure(figsize=(19,5)) >> > >> > For some reason I can't get Qt4Agg creating last two figures in >> > specified >> > sizes. (WXAgg works fine.) >> > >> > matplotlib.__version__ >> > '1.0.svn' >> > >> > matplotlib.__revision__ >> > '$Revision: 8226 $' >> > >> > from PyQt4 import QtCore >> > QtCore.PYQT_VERSION_STR >> > '4.7' >> >> I can reproduce this behavior with a pure pyqt4 example with no mpl >> code, see below. I asked for advice on the pyqt mailing list. >> >> import sys >> from PyQt4 import QtCore, QtGui >> >> class Test(QtGui.QWidget): >> >> def __init__(self, width, height): >> QtGui.QWidget.__init__(self) >> #self.setSizePolicy(QtGui.QSizePolicy.Fixed, >> QtGui.QSizePolicy.Fixed) >> print 'Central widget should have width=%d, height=%d' %(width, >> height) >> self._width = width >> self._height = height >> >> def sizeHint(self): >> return QtCore.QSize(self._width, self._height) >> >> app = QtGui.QApplication([]) >> m = QtGui.QMainWindow() >> c = Test(1000, 700) >> m.setCentralWidget(c) >> m.show() >> s = c.size() >> print 'but central widget has width=%d, height=%d'% (s.width(), >> s.height()) >> sys.exit(app.exec_()) > > Same here with your sample: > > Central widget should have width=1000, height=700 > but central widget has width=960, height=600 > > I resorted to WXAgg for the time being. Waiting for some updates till I hear > a resolution. The annoying part is when I created a plot using specified > width and height Qt4Agg doesn't follow these dimensions as in this case and > resulting savefig(file.pdf) produces wrongly sized file unless I manually > extend the figure area and re-issue a savefig afterwards.
I got a suggestion at the PyQt4 mailing list, and the following patch appears to resolve the problem. However, before I commit the change, I'd like to hear from John or Andrew: What is the protocol for dealing with a change that may affect unit tests? Darren Index: lib/matplotlib/backends/backend_qt4.py =================================================================== --- lib/matplotlib/backends/backend_qt4.py (revision 8292) +++ lib/matplotlib/backends/backend_qt4.py (working copy) @@ -318,6 +318,11 @@ QtCore.QObject.connect(self.toolbar, QtCore.SIGNAL("message"), self.window.statusBar().showMessage) + cs = canvas.sizeHint() + tbs = self.toolbar.sizeHint() + sbs = self.window.statusBar().sizeHint() + self.window.resize(cs.width(), cs.height()+tbs.height()+sbs.height()) + self.window.setCentralWidget(self.canvas) if matplotlib.is_interactive(): ------------------------------------------------------------------------------ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users