

.. _sphx_glr_gallery_user_interfaces_embedding_in_gtk3_sgskip.py:


=================
Embedding In GTK3
=================

demonstrate adding a FigureCanvasGTK3Agg widget to a Gtk.ScrolledWindow
using GTK3 accessed via pygobject



.. code-block:: python


    from gi.repository import Gtk

    from matplotlib.figure import Figure
    from numpy import arange, sin, pi
    from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas

    win = Gtk.Window()
    win.connect("delete-event", 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)

    sw = Gtk.ScrolledWindow()
    win.add(sw)
    # A scrolled window border goes outside the scrollbars and viewport
    sw.set_border_width(10)

    canvas = FigureCanvas(f)  # a Gtk.DrawingArea
    canvas.set_size_request(800, 600)
    sw.add_with_viewport(canvas)

    win.show_all()
    Gtk.main()

**Total running time of the script:** ( 0 minutes  0.000 seconds)



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
