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

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

.. _sphx_glr_gallery_lines_bars_and_markers_line_demo_dash_control.py:


===============================
Dashed line style configuration
===============================

The dashing of a line is controlled via a dash sequence. It can be modified
using `.Line2D.set_dashes`.

The dash sequence is a series of on/off lengths in points, e.g.
``[3, 1]`` would be 3pt long lines separated by 1pt spaces.

Some functions like `.Axes.plot` support passing Line properties as keyword
arguments. In such a case, you can already set the dashing when creating the
line.

*Note*: The dash style can also be configured via a
:ref:`property_cycle <color_cycle>`
by passing a list of dash sequences using the keyword *dashes* to the
cycler. This is not shown within this example.

Other attributes of the dash may also be set either with the relevant method
(`~.Line2D.set_dash_capstyle`, `~.Line2D.set_dash_joinstyle`,
`~.Line2D.set_gapcolor`) or by passing the property through a plotting
function.

.. GENERATED FROM PYTHON SOURCE LINES 26-51

.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np

    x = np.linspace(0, 10, 500)
    y = np.sin(x)

    plt.rc('lines', linewidth=2.5)
    fig, ax = plt.subplots()

    # Using set_dashes() and set_capstyle() to modify dashing of an existing line.
    line1, = ax.plot(x, y, label='Using set_dashes() and set_dash_capstyle()')
    line1.set_dashes([2, 2, 10, 2])  # 2pt line, 2pt break, 10pt line, 2pt break.
    line1.set_dash_capstyle('round')

    # Using plot(..., dashes=...) to set the dashing when creating a line.
    line2, = ax.plot(x, y - 0.2, dashes=[6, 2], label='Using the dashes parameter')

    # Using plot(..., dashes=..., gapcolor=...) to set the dashing and
    # alternating color when creating a line.
    line3, = ax.plot(x, y - 0.4, dashes=[4, 4], gapcolor='tab:pink',
                     label='Using the dashes and gapcolor parameters')

    ax.legend(handlelength=4)
    plt.show()




.. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_line_demo_dash_control_001.png
   :alt: line demo dash control
   :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_line_demo_dash_control_001.png, /gallery/lines_bars_and_markers/images/sphx_glr_line_demo_dash_control_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 52-57

.. tags::

   styling: linestyle
   plot-style: line
   level: beginner


.. _sphx_glr_download_gallery_lines_bars_and_markers_line_demo_dash_control.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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