.. 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_panzoom_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_panzoom_sgskip.py: =========================================== Embedding in GTK4 with a navigation toolbar =========================================== Demonstrate NavigationToolbar with GTK4 accessed via pygobject. .. GENERATED FROM PYTHON SOURCE LINES 8-54 .. code-block:: Python import gi gi.require_version('Gtk', '4.0') from gi.repository import Gtk import numpy as np from matplotlib.backends.backend_gtk4 import \ NavigationToolbar2GTK4 as NavigationToolbar 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(1, 1, 1) t = np.arange(0.0, 3.0, 0.01) s = np.sin(2*np.pi*t) ax.plot(t, s) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) win.set_child(vbox) # Add canvas to vbox canvas = FigureCanvas(fig) # a Gtk.DrawingArea canvas.set_hexpand(True) canvas.set_vexpand(True) vbox.append(canvas) # Create toolbar toolbar = NavigationToolbar(canvas) vbox.append(toolbar) win.show() app = Gtk.Application( application_id='org.matplotlib.examples.EmbeddingInGTK4PanZoom') app.connect('activate', on_activate) app.run(None) .. _sphx_glr_download_gallery_user_interfaces_embedding_in_gtk4_panzoom_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_panzoom_sgskip.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: embedding_in_gtk4_panzoom_sgskip.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_