From 9a1d8ef9f4fbd4cb7e5a3f83a4094741a4b38440 Mon Sep 17 00:00:00 2001 From: Jaco Verster Date: Tue, 25 Oct 2022 09:41:36 +0200 Subject: [PATCH 1/3] removed AngleAnnotation from angle_on_bracket_arrow example --- .../angles_on_bracket_arrows.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 examples/text_labels_and_annotations/angles_on_bracket_arrows.py diff --git a/examples/text_labels_and_annotations/angles_on_bracket_arrows.py b/examples/text_labels_and_annotations/angles_on_bracket_arrows.py new file mode 100644 index 000000000000..b526306c09e6 --- /dev/null +++ b/examples/text_labels_and_annotations/angles_on_bracket_arrows.py @@ -0,0 +1,64 @@ +""" +=================================== +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. +""" + +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(figsize=(8, 7)) +ax.set(xlim=(0, 6), ylim=(-1, 4)) +ax.set_title("Orientation of the bracket arrows relative to angleA and angleB") + +for i, style in enumerate(["]-[", "|-|"]): + for j, angle in enumerate([-40, 60]): + y = 2*i + j + 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") + ax.vlines([i[0] for i in vlines], [y, y], [i[1] for i 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.3, angle, ha="center", + va="center") + +############################################################################# +# +# .. admonition:: References +# +# The use of the following functions, methods, classes and modules is shown +# in this example: +# +# - `matplotlib.patches.ArrowStyle` From c2ad2dd5c227c799fb91c4d98f34506b75709b1b Mon Sep 17 00:00:00 2001 From: jacoverster Date: Tue, 25 Oct 2022 21:12:52 +0200 Subject: [PATCH 2/3] Fixes indentation mistake. --- .../text_labels_and_annotations/angles_on_bracket_arrows.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/text_labels_and_annotations/angles_on_bracket_arrows.py b/examples/text_labels_and_annotations/angles_on_bracket_arrows.py index b526306c09e6..378a64e9dd43 100644 --- a/examples/text_labels_and_annotations/angles_on_bracket_arrows.py +++ b/examples/text_labels_and_annotations/angles_on_bracket_arrows.py @@ -7,7 +7,7 @@ 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. +from the vertical and axes text annotate the angle sizes. """ import matplotlib.pyplot as plt From 298da48ea4cffcef1f414c78258b011275581127 Mon Sep 17 00:00:00 2001 From: Jaco Verster Date: Wed, 26 Oct 2022 09:47:36 +0200 Subject: [PATCH 3/3] rebase to main, remove conflicting commit --- .../angles_on_bracket_arrows.py | 2 +- lib/matplotlib/patches.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/text_labels_and_annotations/angles_on_bracket_arrows.py b/examples/text_labels_and_annotations/angles_on_bracket_arrows.py index 378a64e9dd43..35a6cad22130 100644 --- a/examples/text_labels_and_annotations/angles_on_bracket_arrows.py +++ b/examples/text_labels_and_annotations/angles_on_bracket_arrows.py @@ -51,7 +51,7 @@ def get_point_of_rotated_vertical(origin, line_length, degrees): 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.3, angle, ha="center", + ax.text(vline[0] - dir * 0.15, y + 0.3, f'{angle}°', ha="center", va="center") ############################################################################# diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 76e65859ac73..f61524f65597 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -3119,6 +3119,14 @@ class ArrowStyle(_Style): stroked. This is meant to be used to correct the location of the head so that it does not overshoot the destination point, but not all classes support it. + + Notes + ----- + *angleA* and *angleB* specify the orientation of the bracket, as either a + clockwise or counterclockwise angle depending on the arrow type. 0 degrees + means perpendicular to the line connecting the arrow's head and tail. + + .. plot:: gallery/text_labels_and_annotations/angles_on_bracket_arrows.py """ _style_list = {} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy