Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTK3 backend: implemented FigureCanvasBase.resize_event() #2867

Merged
merged 1 commit into from Mar 6, 2014

Conversation

timovwb
Copy link
Contributor

@timovwb timovwb commented Mar 5, 2014

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:

# 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.

@tacaswell tacaswell added this to the v1.4.0 milestone Mar 5, 2014
@fariza
Copy link
Member

fariza commented Mar 6, 2014

I like, until now it I don't see any bad side effects

tacaswell added a commit that referenced this pull request Mar 6, 2014
GTK3 backend: implemented FigureCanvasBase.resize_event()
@tacaswell tacaswell merged commit 93de066 into matplotlib:master Mar 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants