We're updating the default styles for Matplotlib 2.0

Learn what to expect in the new updates


Previous topic

user_interfaces Examples

Next topic

user_interfaces example code: embedding_in_gtk2.py

This Page

user_interfaces example code: embedding_in_gtk.pyΒΆ

[source code]

#!/usr/bin/env python
show how to add a matplotlib FigureCanvasGTK or FigureCanvasGTKAgg widget to a

import gtk

from matplotlib.figure import Figure
from numpy import arange, sin, pi

# uncomment to select /GTK/GTKAgg/GTKCairo
#from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
#from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas

win = gtk.Window()
win.connect("destroy", lambda x: gtk.main_quit())
win.set_default_size(400, 300)
win.set_title("Embedding in GTK")

f = Figure(figsize=(5, 4), dpi=100)
a = f.add_subplot(111)
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
a.plot(t, s)

canvas = FigureCanvas(f)  # a gtk.DrawingArea


Keywords: python, matplotlib, pylab, example, codex (see Search examples)