.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/user_interfaces/embedding_in_gtk4_sgskip.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_user_interfaces_embedding_in_gtk4_sgskip.py: ================= Embedding in GTK4 ================= Demonstrate adding a FigureCanvasGTK4Agg widget to a Gtk.ScrolledWindow using GTK4 accessed via pygobject. .. GENERATED FROM PYTHON SOURCE LINES 9-48 .. code-block:: Python import gi gi.require_version('Gtk', '4.0') from gi.repository import Gtk import numpy as np from matplotlib.backends.backend_gtk4agg import \ FigureCanvasGTK4Agg as FigureCanvas from matplotlib.figure import Figure def on_activate(app): win = Gtk.ApplicationWindow(application=app) win.set_default_size(400, 300) win.set_title("Embedding in GTK4") 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) # A scrolled margin goes outside the scrollbars and viewport. sw = Gtk.ScrolledWindow(margin_top=10, margin_bottom=10, margin_start=10, margin_end=10) win.set_child(sw) canvas = FigureCanvas(fig) # a Gtk.DrawingArea canvas.set_size_request(800, 600) sw.set_child(canvas) win.show() app = Gtk.Application(application_id='org.matplotlib.examples.EmbeddingInGTK4') app.connect('activate', on_activate) app.run(None) .. _sphx_glr_download_gallery_user_interfaces_embedding_in_gtk4_sgskip.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: embedding_in_gtk4_sgskip.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: embedding_in_gtk4_sgskip.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_