
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/subplots_axes_and_figures/broken_axis.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_subplots_axes_and_figures_broken_axis.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_subplots_axes_and_figures_broken_axis.py:


===========
Broken axis
===========

Broken axis example, where the y-axis will have a portion cut out.

.. GENERATED FROM PYTHON SOURCE LINES 8-56

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    np.random.seed(19680801)

    pts = np.random.rand(30)*.2
    # Now let's make two outlier points which are far away from everything.
    pts[[3, 14]] += .8

    # If we were to simply plot pts, we'd lose most of the interesting
    # details due to the outliers. So let's 'break' or 'cut-out' the y-axis
    # into two portions - use the top (ax1) for the outliers, and the bottom
    # (ax2) for the details of the majority of our data
    fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
    fig.subplots_adjust(hspace=0.05)  # adjust space between Axes

    # plot the same data on both Axes
    ax1.plot(pts)
    ax2.plot(pts)

    # zoom-in / limit the view to different portions of the data
    ax1.set_ylim(.78, 1.)  # outliers only
    ax2.set_ylim(0, .22)  # most of the data

    # hide the spines between ax and ax2
    ax1.spines.bottom.set_visible(False)
    ax2.spines.top.set_visible(False)
    ax1.xaxis.tick_top()
    ax1.tick_params(labeltop=False)  # don't put tick labels at the top
    ax2.xaxis.tick_bottom()

    # Now, let's turn towards the cut-out slanted lines.
    # We create line objects in axes coordinates, in which (0,0), (0,1),
    # (1,0), and (1,1) are the four corners of the Axes.
    # The slanted lines themselves are markers at those locations, such that the
    # lines keep their angle and position, independent of the Axes size or scale
    # Finally, we need to disable clipping.

    d = .5  # proportion of vertical to horizontal extent of the slanted line
    kwargs = dict(marker=[(-1, -d), (1, d)], markersize=12,
                  linestyle="none", color='k', mec='k', mew=1, clip_on=False)
    ax1.plot([0, 1], [0, 0], transform=ax1.transAxes, **kwargs)
    ax2.plot([0, 1], [1, 1], transform=ax2.transAxes, **kwargs)


    plt.show()


.. GENERATED FROM PYTHON SOURCE LINES 57-62

.. tags::

   component: axis
   plot-type: line
   level: intermediate


.. _sphx_glr_download_gallery_subplots_axes_and_figures_broken_axis.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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