matplotlib/matplotlib — pull request #2867 by timovwb (2014-03-05 12:44:45+00:00)
Title: GTK3 backend: implemented FigureCanvasBase.resize_event()

This pull request implements the FigureCanvasBase.resize_event() to the GTK3 backend, which will allow to connect to mpl_connect("resize_event", func).

Consider following animation example:

```python
# Modified example from http://matplotlib.org/examples/animation/simple_anim.html
import numpy as np
import matplotlib as mpl
import matplotlib.animation as animation
from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas

from gi.repository import Gtk

class TestWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.resize(600, 400)

figure = mpl.figure.Figure()
canvas = FigureCanvas(figure)
self.add(canvas)
self.show_all()

x = np.arange(0, 2*np.pi, 0.01)

ax1 = figure.add_subplot(121)
line1, = ax1.plot(x, np.sin(x))

ax2 = figure.add_subplot(122)
line2, = ax2.plot(x, np.sin(x))

def animate(i):
line1.set_ydata(np.sin(x+i/10.0))
line2.set_ydata(np.sin(x+i/10.0))
return line1, line2

def init():
line1.set_ydata(np.ma.array(x, mask=True))
line2.set_ydata(np.ma.array(x, mask=True))
return line1, line2

self.ani = animation.FuncAnimation(figure, animate, np.arange(1, 200), init_func=init,
interval=25, blit=True)

if __name__ == "__main__":
win = TestWindow()
win.connect("delete-event", Gtk.main_quit)
Gtk.main()
```

Without the patch, resize the window to see major redraw issues which makes the plot unusable. When using the blit option, the animation will connect to the resize_event signal to correctly redraw the plot when resized, which isn't available in the GTK3 backend. With the changes applied, resizing works without problems.

The patch is inspired by the Qt4 and wx backends, but comments from someone with more Matplotlib experience is greatly appreciated.