{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Matplotlib with Glade 3\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from pathlib import Path\n\nimport gi\n\ngi.require_version('Gtk', '3.0')\nfrom gi.repository import Gtk\n\nimport numpy as np\n\nfrom matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas\nfrom matplotlib.figure import Figure\n\n\nclass Window1Signals:\n    def on_window1_destroy(self, widget):\n        Gtk.main_quit()\n\n\ndef main():\n    builder = Gtk.Builder()\n    builder.add_objects_from_file(\n        str(Path(__file__).parent / \"mpl_with_glade3.glade\"),\n        (\"window1\", \"\"))\n    builder.connect_signals(Window1Signals())\n    window = builder.get_object(\"window1\")\n    sw = builder.get_object(\"scrolledwindow1\")\n\n    # Start of Matplotlib specific code\n    figure = Figure(figsize=(8, 6), dpi=71)\n    axis = figure.add_subplot()\n    t = np.arange(0.0, 3.0, 0.01)\n    s = np.sin(2*np.pi*t)\n    axis.plot(t, s)\n\n    axis.set_xlabel('time [s]')\n    axis.set_ylabel('voltage [V]')\n\n    canvas = FigureCanvas(figure)  # a Gtk.DrawingArea\n    canvas.set_size_request(800, 600)\n    sw.add(canvas)\n    # End of Matplotlib specific code\n\n    window.show_all()\n    Gtk.main()\n\nif __name__ == \"__main__\":\n    main()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}