

.. _sphx_glr_gallery_lines_bars_and_markers_line_demo_dash_control.py:


=======================================
A simple plot with a custom dashed line
=======================================

A Line object's ``set_dashes`` method allows you to specify dashes with
a series of on/off lengths (in points).




.. image:: /gallery/lines_bars_and_markers/images/sphx_glr_line_demo_dash_control_001.png
    :align: center





.. code-block:: python

    import numpy as np
    import matplotlib.pyplot as plt


    x = np.linspace(0, 10, 500)
    dashes = [10, 5, 100, 5]  # 10 points on, 5 off, 100 on, 5 off

    fig, ax = plt.subplots()
    line1, = ax.plot(x, np.sin(x), '--', linewidth=2,
                     label='Dashes set retroactively')
    line1.set_dashes(dashes)

    line2, = ax.plot(x, -1 * np.sin(x), dashes=[30, 5, 10, 5],
                     label='Dashes set proactively')

    ax.legend(loc='lower right')
    plt.show()

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



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

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