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

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

.. _sphx_glr_gallery_text_labels_and_annotations_angles_on_bracket_arrows.py:


===================================
Angle annotations on bracket arrows
===================================

This example shows how to add angle annotations to bracket arrow styles
created using `.FancyArrowPatch`. *angleA* and *angleB* are measured from a
vertical line as positive (to the left) or negative (to the right). Blue
`.FancyArrowPatch` arrows indicate the directions of *angleA* and *angleB*
from the vertical and axes text annotate the angle sizes.

.. GENERATED FROM PYTHON SOURCE LINES 12-60

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib.patches import FancyArrowPatch


    def get_point_of_rotated_vertical(origin, line_length, degrees):
        """Return xy coordinates of the vertical line end rotated by degrees."""
        rad = np.deg2rad(-degrees)
        return [origin[0] + line_length * np.sin(rad),
                origin[1] + line_length * np.cos(rad)]


    fig, ax = plt.subplots()
    ax.set(xlim=(0, 6), ylim=(-1, 5))
    ax.set_title("Orientation of the bracket arrows relative to angleA and angleB")

    style = ']-['
    for i, angle in enumerate([-40, 0, 60]):
        y = 2*i
        arrow_centers = ((1, y), (5, y))
        vlines = ((1, y + 0.5), (5, y + 0.5))
        anglesAB = (angle, -angle)
        bracketstyle = f"{style}, angleA={anglesAB[0]}, angleB={anglesAB[1]}"
        bracket = FancyArrowPatch(*arrow_centers, arrowstyle=bracketstyle,
                                  mutation_scale=42)
        ax.add_patch(bracket)
        ax.text(3, y + 0.05, bracketstyle, ha="center", va="bottom", fontsize=14)
        ax.vlines([line[0] for line in vlines], [y, y], [line[1] for line in vlines],
                  linestyles="--", color="C0")
        # Get the top coordinates for the drawn patches at A and B
        patch_tops = [get_point_of_rotated_vertical(center, 0.5, angle)
                      for center, angle in zip(arrow_centers, anglesAB)]
        # Define the connection directions for the annotation arrows
        connection_dirs = (1, -1) if angle > 0 else (-1, 1)
        # Add arrows and annotation text
        arrowstyle = "Simple, tail_width=0.5, head_width=4, head_length=8"
        for vline, dir, patch_top, angle in zip(vlines, connection_dirs,
                                                patch_tops, anglesAB):
            kw = dict(connectionstyle=f"arc3,rad={dir * 0.5}",
                      arrowstyle=arrowstyle, color="C0")
            ax.add_patch(FancyArrowPatch(vline, patch_top, **kw))
            ax.text(vline[0] - dir * 0.15, y + 0.7, f'{angle}°', ha="center",
                    va="center")

    plt.show()




.. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_angles_on_bracket_arrows_001.png
   :alt: Orientation of the bracket arrows relative to angleA and angleB
   :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_angles_on_bracket_arrows_001.png, /gallery/text_labels_and_annotations/images/sphx_glr_angles_on_bracket_arrows_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 61-67

.. admonition:: References

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

   - `matplotlib.patches.ArrowStyle`


.. _sphx_glr_download_gallery_text_labels_and_annotations_angles_on_bracket_arrows.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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