Matplotlib + Qt: tight_layout() doesn't work on the first draw
Using PyQt4 and matplotlib I have connected a button click to perform some
calculation and render a graph. The tight_layout() only applies after
clicking the button a second time.
When I'm done setting up the axes and putting data on the graph, I call
fig.tight_layout()
fig.canvas.draw()
I've tried to fake a second button press without success:
from PyQt4 import QtGui
QtGui.QApplication.processEvents()
fig.tight_layout()
fig.canvas.draw()
QtGui.QApplication.processEvents()
fig.tight_layout()
fig.canvas.draw()
My thought was that the Qt surface wasn't recognized as dirty, but
resizing the window redraws the chart with the same loose layout. The
tight layout does apply when I clear the axes and repopulate the chart.
How can I make tight_layout() apply the first time the graph is drawn?
No comments:
Post a Comment