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

.. only:: html

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

        Click :ref:`here <sphx_glr_download_gallery_subplots_axes_and_figures_axes_demo.py>`
        to download the full example code

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

.. _sphx_glr_gallery_subplots_axes_and_figures_axes_demo.py:


=========
Axes Demo
=========

Example use of ``fig.add_axes`` to create inset axes within the main plot axes.

Please see also the :ref:`axes_grid_examples` section, and the following three
examples:

- :doc:`/gallery/subplots_axes_and_figures/zoom_inset_axes`
- :doc:`/gallery/axes_grid1/inset_locator_demo`
- :doc:`/gallery/axes_grid1/inset_locator_demo2`

.. GENERATED FROM PYTHON SOURCE LINES 15-46



.. image:: /gallery/subplots_axes_and_figures/images/sphx_glr_axes_demo_001.png
    :alt: Gaussian colored noise, Probability, Impulse response
    :class: sphx-glr-single-img





.. code-block:: default

    import matplotlib.pyplot as plt
    import numpy as np

    np.random.seed(19680801)  # Fixing random state for reproducibility.

    # create some data to use for the plot
    dt = 0.001
    t = np.arange(0.0, 10.0, dt)
    r = np.exp(-t[:1000] / 0.05)  # impulse response
    x = np.random.randn(len(t))
    s = np.convolve(x, r)[:len(x)] * dt  # colored noise

    fig, main_ax = plt.subplots()
    main_ax.plot(t, s)
    main_ax.set_xlim(0, 1)
    main_ax.set_ylim(1.1 * np.min(s), 2 * np.max(s))
    main_ax.set_xlabel('time (s)')
    main_ax.set_ylabel('current (nA)')
    main_ax.set_title('Gaussian colored noise')

    # this is an inset axes over the main axes
    right_inset_ax = fig.add_axes([.65, .6, .2, .2], facecolor='k')
    right_inset_ax.hist(s, 400, density=True)
    right_inset_ax.set(title='Probability', xticks=[], yticks=[])

    # this is another inset axes over the main axes
    left_inset_ax = fig.add_axes([.2, .6, .2, .2], facecolor='k')
    left_inset_ax.plot(t[:len(r)], r)
    left_inset_ax.set(title='Impulse response', xlim=(0, .2), xticks=[], yticks=[])

    plt.show()


.. rst-class:: sphx-glr-timing

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


.. _sphx_glr_download_gallery_subplots_axes_and_figures_axes_demo.py:


.. only :: html

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



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

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



  .. container:: sphx-glr-download sphx-glr-download-jupyter

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