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

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

.. _sphx_glr_gallery_lines_bars_and_markers_axline.py:


==============
Infinite lines
==============

`~.axes.Axes.axvline` and `~.axes.Axes.axhline` draw infinite vertical /
horizontal lines, at given *x* / *y* positions. They are usually used to mark
special data values, e.g. in this example the center and limit values of the
sigmoid function.

`~.axes.Axes.axline` draws infinite straight lines in arbitrary directions.

.. redirect-from:: /gallery/pyplot/axline

.. GENERATED FROM PYTHON SOURCE LINES 15-33

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    t = np.linspace(-10, 10, 100)
    sig = 1 / (1 + np.exp(-t))

    fig, ax = plt.subplots()
    ax.axhline(y=0, color="black", linestyle="--")
    ax.axhline(y=0.5, color="black", linestyle=":")
    ax.axhline(y=1.0, color="black", linestyle="--")
    ax.axvline(color="grey")
    ax.axline((0, 0.5), slope=0.25, color="black", linestyle=(0, (5, 5)))
    ax.plot(t, sig, linewidth=2, label=r"$\sigma(t) = \frac{1}{1 + e^{-t}}$")
    ax.set(xlim=(-10, 10), xlabel="t")
    ax.legend(fontsize=14)
    plt.show()




.. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_axline_001.png
   :alt: axline
   :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_axline_001.png, /gallery/lines_bars_and_markers/images/sphx_glr_axline_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 34-38

`~.axes.Axes.axline` can also be used with a *transform* parameter, which
applies to the point, but not to the slope. This can be useful for drawing
diagonal grid lines with a fixed slope, which stay in place when the
plot limits are moved.

.. GENERATED FROM PYTHON SOURCE LINES 38-46

.. code-block:: Python


    fig, ax = plt.subplots()
    for pos in np.linspace(-2, 1, 10):
        ax.axline((pos, 0), slope=0.5, color='k', transform=ax.transAxes)

    ax.set(xlim=(0, 1), ylim=(0, 1))
    plt.show()




.. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_axline_002.png
   :alt: axline
   :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_axline_002.png, /gallery/lines_bars_and_markers/images/sphx_glr_axline_002_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 47-63

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.axes.Axes.axhline` / `matplotlib.pyplot.axhline`
   - `matplotlib.axes.Axes.axvline` / `matplotlib.pyplot.axvline`
   - `matplotlib.axes.Axes.axline` / `matplotlib.pyplot.axline`


.. seealso::

   `~.Axes.axhspan`, `~.Axes.axvspan` draw rectangles that span the Axes in one
   direction and are bounded in the other direction.

.. tags:: component: annotation


.. _sphx_glr_download_gallery_lines_bars_and_markers_axline.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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