注释
转到末尾 下载完整示例代码。
嵌入 GTK3#
演示将 FigureCanvasGTK3Agg 小部件添加到使用 pygobject 访问的 GTK3 的 Gtk.ScrolledWindow。
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import numpy as np
from matplotlib.backends.backend_gtk3agg import \
FigureCanvasGTK3Agg as FigureCanvas
from matplotlib.figure import Figure
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.set_default_size(400, 300)
win.set_title("Embedding in GTK3")
fig = Figure(figsize=(5, 4), dpi=100)
ax = fig.add_subplot()
t = np.arange(0.0, 3.0, 0.01)
s = np.sin(2*np.pi*t)
ax.plot(t, s)
sw = Gtk.ScrolledWindow()
win.add(sw)
# A scrolled window border goes outside the scrollbars and viewport
sw.set_border_width(10)
canvas = FigureCanvas(fig) # a Gtk.DrawingArea
canvas.set_size_request(800, 600)
sw.add(canvas)
win.show_all()
Gtk.main()