Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement head resizing (and reversal) for larrow/rarrow/darrow #29998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2f366fa
Make arrow annotation arrowhead adjustable
Abitamim Dec 16, 2022
e8d7eb7
Add test - not sure if correct
Abitamim Dec 16, 2022
15bd7dc
Update tutorial
Abitamim Dec 16, 2022
4f57495
Fixed linting
Abitamim Dec 16, 2022
5c3fa60
Add reversed arrow-head support to larrow/rarrow
CharlieThornton33 Apr 17, 2025
8065549
Fix reversed arrow-head support for single arrows, handle edge cases
CharlieThornton33 Apr 20, 2025
0471e92
Add support for reversed arrow-heads and edge cases in DArrow, update…
CharlieThornton33 Apr 20, 2025
212cbc9
Update docstings, add what's new notes
CharlieThornton33 Apr 22, 2025
273a2fe
Fix typo in DArrow drawing code
CharlieThornton33 Apr 28, 2025
bf2d06b
Fixed padding inconsistency: reverted breaking API change
CharlieThornton33 Apr 28, 2025
0ea2f5a
Fix what's new example
CharlieThornton33 Apr 28, 2025
d7fd405
Create unit test for boxarrow head adjustment
CharlieThornton33 Apr 30, 2025
ff34b4b
Fixed linting
CharlieThornton33 Apr 30, 2025
d9b0b32
Update new test to use mpl20 figure style
CharlieThornton33 May 1, 2025
f3369c0
Changed padding for LArrow/RArrow to prevent text spilling out
CharlieThornton33 May 14, 2025
3913ef6
[skip ci] Fix spelling mistake in LArrow padding code
CharlieThornton33 May 14, 2025
63a4ba9
Remove 'poking-out' behaviour from reversed arrow-heads, add padding …
CharlieThornton33 Jun 19, 2025
7ed9fd1
Remove now-unneeded manual padding from What's New page
CharlieThornton33 Jun 19, 2025
d953aef
Remove test_boxarrow_adjustment
CharlieThornton33 Jun 19, 2025
d2105da
Prevent text overspill from DArrows using padding
CharlieThornton33 Jun 19, 2025
54147e6
Added test for arrow-head adjustments
CharlieThornton33 Jun 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions doc/users/next_whats_new/box_arrow_size_controls.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Arrow-style sub-classes of ``BoxStyle`` support arrow head resizing
-------------------------------------------------------------------

The new *head_width* and *head_angle* parameters to
`.BoxStyle.LArrow`, `.BoxStyle.RArrow` and `.BoxStyle.DArrow` allow for adjustment
of the size and aspect ratio of the arrow heads used.

By using negative angles (or corresponding reflex angles) for *head_angle*, arrows
with 'backwards' heads may be created.

.. plot::
:include-source: false
:alt: A plot containing two arrow-shaped text boxes. One arrow has a pentagonal 'road-sign' shape, and the other an inverted arrow head on each end.

import numpy as np
import matplotlib.pyplot as plt

# Data for plotting; here, an intensity distribution for Fraunhofer diffraction
# from 7 thin slits
x_data = np.linspace(-3 * np.pi, 3 * np.pi, num=1000)
I_data = (np.sin(x_data * 3.5) / np.sin(x_data / 2)) ** 2

# Generate plot

fig, ax = plt.subplots()
plt.plot(x_data, I_data)

plt.xlim(-3 * np.pi, 3 * np.pi)
plt.ylim(0, 50)

#
# Annotate with boxed text in arrows
#

# head_width=1 gives 'road-sign' shape
t1 = ax.text(-1, 35, "Primary maximum",
ha="right", va="center", rotation=30, size=10,
bbox=dict(boxstyle="rarrow,pad=0.3,head_width=1,head_angle=60",
fc="lightblue", ec="steelblue", lw=2))

# Negative head_angle gives reversed arrow heads
t2 = ax.text(np.pi, 30, "Lower intensity",
ha="center", va="center", rotation=0, size=10,
bbox=dict(boxstyle="darrow,pad=0.3,head_width=2,head_angle=-80",
fc="lightblue", ec="steelblue", lw=2))


plt.show()
32 changes: 16 additions & 16 deletions galleries/users_explain/text/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,20 @@
# The arguments are the name of the box style with its attributes as
# keyword arguments. Currently, following box styles are implemented:
#
# ========== ============== ==========================
# Class Name Attrs
# ========== ============== ==========================
# Circle ``circle`` pad=0.3
# DArrow ``darrow`` pad=0.3
# Ellipse ``ellipse`` pad=0.3
# LArrow ``larrow`` pad=0.3
# RArrow ``rarrow`` pad=0.3
# Round ``round`` pad=0.3,rounding_size=None
# Round4 ``round4`` pad=0.3,rounding_size=None
# Roundtooth ``roundtooth`` pad=0.3,tooth_size=None
# Sawtooth ``sawtooth`` pad=0.3,tooth_size=None
# Square ``square`` pad=0.3
# ========== ============== ==========================
# ========== ============== ==========================
# Class Name Attrs
# ========== ============== ==========================
# Circle ``circle`` pad=0.3
# DArrow ``darrow`` pad=0.3,head_width=1.5,head_angle=90
# Ellipse ``ellipse`` pad=0.3
# LArrow ``larrow`` pad=0.3,head_width=1.5,head_angle=90
# RArrow ``rarrow`` pad=0.3,head_width=1.5,head_angle=90
# Round ``round`` pad=0.3,rounding_size=None
# Round4 ``round4`` pad=0.3,rounding_size=None
# Roundtooth ``roundtooth`` pad=0.3,tooth_size=None
# Sawtooth ``sawtooth`` pad=0.3,tooth_size=None
# Square ``square`` pad=0.3
# ========== ============== ==========================
#
# .. figure:: /gallery/shapes_and_collections/images/sphx_glr_fancybox_demo_001.png
# :target: /gallery/shapes_and_collections/fancybox_demo.html
Expand Down Expand Up @@ -303,8 +303,8 @@ def custom_box_style(x0, y0, width, height, mutation_size):
x0, y0 = x0 - pad, y0 - pad
x1, y1 = x0 + width, y0 + height
# return the new path
return Path([(x0, y0), (x1, y0), (x1, y1), (x0, y1),
(x0-pad, (y0+y1)/2), (x0, y0), (x0, y0)],
return Path([(x0, y0), (x1, y0), (x1, y1), (x0, y1), (x0, y1-pad),
(x0-pad, (y0+y1)/2), (x0, y0+pad), (x0, y0), (x0, y0)],
closed=True)

fig, ax = plt.subplots(figsize=(3, 3))
Expand Down
Loading
Loading