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

    Click :ref:`here <sphx_glr_download_gallery_api_agg_oo_sgskip.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_api_agg_oo_sgskip.py:


=============================
The object-oriented interface
=============================

A pure OO (look Ma, no pyplot!) example using the agg backend.



.. code-block:: python


    from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
    from matplotlib.figure import Figure

    fig = Figure()
    # A canvas must be manually attached to the figure (pyplot would automatically
    # do it).  This is done by instantiating the canvas with the figure as
    # argument.
    FigureCanvas(fig)
    ax = fig.add_subplot(111)
    ax.plot([1, 2, 3])
    ax.set_title('hi mom')
    ax.grid(True)
    ax.set_xlabel('time')
    ax.set_ylabel('volts')
    fig.savefig('test')


.. _sphx_glr_download_gallery_api_agg_oo_sgskip.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: agg_oo_sgskip.ipynb <agg_oo_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>`_
