I have an embedded matplotlib plot in a PyQt4 application. This is the plotting widget I have made based on the Qt4 embedding sample at http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html. Unfortunately, every time I add a new plot, this graph shrinks slightly. I have two plot widgets aligned side by side in a QGridLayout if that makes a difference.
What could the reason for this weird behaviour be?
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)
I fixed this using setFixedSize on the widget instead of allowing the layout manager to resize. I dont understand why the layout manager would want to shrink the widget when more plots were added but the problem is fixed anyway
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With