
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/user_interfaces/embedding_in_wx5_sgskip.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

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

        :ref:`Go to the end <sphx_glr_download_gallery_user_interfaces_embedding_in_wx5_sgskip.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_user_interfaces_embedding_in_wx5_sgskip.py:


==============
Embed in wx #5
==============

.. GENERATED FROM PYTHON SOURCE LINES 7-63

.. code-block:: Python


    import wx
    import wx.lib.agw.aui as aui
    import wx.lib.mixins.inspection as wit

    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
    from matplotlib.backends.backend_wxagg import \
        NavigationToolbar2WxAgg as NavigationToolbar
    from matplotlib.figure import Figure


    class Plot(wx.Panel):
        def __init__(self, parent, id=-1, dpi=None, **kwargs):
            super().__init__(parent, id=id, **kwargs)
            self.figure = Figure(dpi=dpi, figsize=(2, 2))
            self.canvas = FigureCanvas(self, -1, self.figure)
            self.toolbar = NavigationToolbar(self.canvas)
            self.toolbar.Realize()

            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(self.canvas, 1, wx.EXPAND)
            sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
            self.SetSizer(sizer)


    class PlotNotebook(wx.Panel):
        def __init__(self, parent, id=-1):
            super().__init__(parent, id=id)
            self.nb = aui.AuiNotebook(self)
            sizer = wx.BoxSizer()
            sizer.Add(self.nb, 1, wx.EXPAND)
            self.SetSizer(sizer)

        def add(self, name="plot"):
            page = Plot(self.nb)
            self.nb.AddPage(page, name)
            return page.figure


    def demo():
        # Alternatively you could use:
        # app = wx.App()
        # InspectableApp is a great debug tool, see:
        # http://wiki.wxpython.org/Widget%20Inspection%20Tool
        app = wit.InspectableApp()
        frame = wx.Frame(None, -1, 'Plotter')
        plotter = PlotNotebook(frame)
        axes1 = plotter.add('figure 1').add_subplot()
        axes1.plot([1, 2, 3], [2, 1, 4])
        axes2 = plotter.add('figure 2').add_subplot()
        axes2.plot([1, 2, 3, 4, 5], [2, 1, 4, 2, 3])
        frame.Show()
        app.MainLoop()

    if __name__ == "__main__":
        demo()


.. _sphx_glr_download_gallery_user_interfaces_embedding_in_wx5_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_wx5_sgskip.ipynb <embedding_in_wx5_sgskip.ipynb>`

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: embedding_in_wx5_sgskip.zip <embedding_in_wx5_sgskip.zip>`


.. only:: html

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

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
