
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/lines_bars_and_markers/joinstyle.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_gallery_lines_bars_and_markers_joinstyle.py>`
        to download the full example code

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

.. _sphx_glr_gallery_lines_bars_and_markers_joinstyle.py:


==========================
Join styles and cap styles
==========================

This example demonstrates the available join styles and cap styles.

Both are used in `.Line2D` and various ``Collections`` from
`matplotlib.collections` as well as some functions that create these, e.g.
`~matplotlib.pyplot.plot`.


Join styles
===========

Join styles define how the connection between two line segments is drawn.

See the respective ``solid_joinstyle``, ``dash_joinstyle`` or ``joinstyle``
parameters.

.. GENERATED FROM PYTHON SOURCE LINES 21-52

.. code-block:: default


    import numpy as np
    import matplotlib.pyplot as plt


    def plot_angle(ax, x, y, angle, style):
        phi = np.radians(angle)
        xx = [x + .5, x, x + .5*np.cos(phi)]
        yy = [y, y, y + .5*np.sin(phi)]
        ax.plot(xx, yy, lw=12, color='tab:blue', solid_joinstyle=style)
        ax.plot(xx, yy, lw=1, color='black')
        ax.plot(xx[1], yy[1], 'o', color='tab:red', markersize=3)


    fig, ax = plt.subplots(figsize=(8, 6))
    ax.set_title('Join style')

    for x, style in enumerate(['miter', 'round', 'bevel']):
        ax.text(x, 5, style)
        for y, angle in enumerate([20, 45, 60, 90, 120]):
            plot_angle(ax, x, y, angle, style)
            if x == 0:
                ax.text(-1.3, y, f'{angle} degrees')
    ax.text(1, 4.7, '(default)')

    ax.set_xlim(-1.5, 2.75)
    ax.set_ylim(-.5, 5.5)
    ax.set_axis_off()
    plt.show()





.. image:: /gallery/lines_bars_and_markers/images/sphx_glr_joinstyle_001.png
    :alt: Join style
    :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 53-60

Cap styles
==========

Cap styles define how the the end of a line is drawn.

See the respective ``solid_capstyle``, ``dash_capstyle`` or ``capstyle``
parameters.

.. GENERATED FROM PYTHON SOURCE LINES 61-78

.. code-block:: default


    fig, ax = plt.subplots(figsize=(8, 2))
    ax.set_title('Cap style')

    for x, style in enumerate(['butt', 'round', 'projecting']):
        ax.text(x+0.25, 1, style, ha='center')
        xx = [x, x+0.5]
        yy = [0, 0]
        ax.plot(xx, yy, lw=12, color='tab:blue', solid_capstyle=style)
        ax.plot(xx, yy, lw=1, color='black')
        ax.plot(xx, yy, 'o', color='tab:red', markersize=3)
    ax.text(2.25, 0.7, '(default)', ha='center')

    ax.set_ylim(-.5, 1.5)
    ax.set_axis_off()





.. image:: /gallery/lines_bars_and_markers/images/sphx_glr_joinstyle_002.png
    :alt: Cap style
    :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 79-86

------------

References
""""""""""

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

.. GENERATED FROM PYTHON SOURCE LINES 87-91

.. code-block:: default


    import matplotlib
    matplotlib.axes.Axes.plot
    matplotlib.pyplot.plot




.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none


    <function plot at 0x7f73be827ee0>




.. rst-class:: sphx-glr-timing

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


.. _sphx_glr_download_gallery_lines_bars_and_markers_joinstyle.py:


.. only :: html

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



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

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



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

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
