{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Embed in wx #5\n\n.. tip::\n\n    As a development and debugging aid, you can replace :class:`wx.App`\n    by :class:`wx.lib.mixins.inspection.InspectableApp`.\n    This adds the capability to start the [Widget Inspection Tool](https://wiki.wxpython.org/How%20to%20use%20Widget%20Inspection%20Tool%20-%20WIT%20%28Phoenix%29)\n    via :kbd:`Ctrl-Alt-I`.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import wx\nimport wx.lib.agw.aui as aui\n\nfrom matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas\nfrom matplotlib.backends.backend_wxagg import \\\n    NavigationToolbar2WxAgg as NavigationToolbar\nfrom matplotlib.figure import Figure\n\n\nclass Plot(wx.Panel):\n    def __init__(self, parent, id=-1, dpi=None, **kwargs):\n        super().__init__(parent, id=id, **kwargs)\n        self.figure = Figure(dpi=dpi, figsize=(2, 2))\n        self.canvas = FigureCanvas(self, -1, self.figure)\n        self.toolbar = NavigationToolbar(self.canvas)\n        self.toolbar.Realize()\n\n        sizer = wx.BoxSizer(wx.VERTICAL)\n        sizer.Add(self.canvas, 1, wx.EXPAND)\n        sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)\n        self.SetSizer(sizer)\n\n\nclass PlotNotebook(wx.Panel):\n    def __init__(self, parent, id=-1):\n        super().__init__(parent, id=id)\n        self.nb = aui.AuiNotebook(self)\n        sizer = wx.BoxSizer()\n        sizer.Add(self.nb, 1, wx.EXPAND)\n        self.SetSizer(sizer)\n\n    def add(self, name=\"plot\"):\n        page = Plot(self.nb)\n        self.nb.AddPage(page, name)\n        return page.figure\n\n\ndef demo():\n    app = wx.App()\n    frame = wx.Frame(None, -1, 'Plotter')\n    plotter = PlotNotebook(frame)\n    axes1 = plotter.add('figure 1').add_subplot()\n    axes1.plot([1, 2, 3], [2, 1, 4])\n    axes2 = plotter.add('figure 2').add_subplot()\n    axes2.plot([1, 2, 3, 4, 5], [2, 1, 4, 2, 3])\n    frame.Show()\n    app.MainLoop()\n\nif __name__ == \"__main__\":\n    demo()"
      ]
    }
  ],
  "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
}