

.. _sphx_glr_gallery_subplots_axes_and_figures_axes_demo.py:


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

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




.. image:: /gallery/subplots_axes_and_figures/images/sphx_glr_axes_demo_001.png
    :align: center





.. code-block:: python

    import matplotlib.pyplot as plt
    import numpy as np

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


    # 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

    # the main axes is subplot(111) by default
    plt.plot(t, s)
    plt.axis([0, 1, 1.1 * np.min(s), 2 * np.max(s)])
    plt.xlabel('time (s)')
    plt.ylabel('current (nA)')
    plt.title('Gaussian colored noise')

    # this is an inset axes over the main axes
    a = plt.axes([.65, .6, .2, .2], facecolor='k')
    n, bins, patches = plt.hist(s, 400, normed=1)
    plt.title('Probability')
    plt.xticks([])
    plt.yticks([])

    # this is another inset axes over the main axes
    a = plt.axes([0.2, 0.6, .2, .2], facecolor='k')
    plt.plot(t[:len(r)], r)
    plt.title('Impulse response')
    plt.xlim(0, 0.2)
    plt.xticks([])
    plt.yticks([])

    plt.show()

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



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: axes_demo.ipynb <axes_demo.ipynb>`


.. only:: html

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

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