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

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_gallery_user_interfaces_embedding_in_gtk4_sgskip.py>`
        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-46

.. code-block:: default


    import gi
    gi.require_version('Gtk', '4.0')
    from gi.repository import Gtk

    from matplotlib.backends.backend_gtk4agg import (
        FigureCanvasGTK4Agg as FigureCanvas)
    from matplotlib.figure import Figure
    import numpy as np


    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
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: embedding_in_gtk4_sgskip.py <embedding_in_gtk4_sgskip.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: embedding_in_gtk4_sgskip.ipynb <embedding_in_gtk4_sgskip.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
