Skip to content
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
38 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
b5ba28e
Fix padding from straight-edges of reversed arrow heads, fix incorrec…
CharlieThornton33 Jul 5, 2025
976e54b
[skip ci] Fix indentation in galleries/users_explain/text/annotations.py
CharlieThornton33 Jul 9, 2025
a08c67b
[skip ci] Use python % operator rather than np.mod() to act on scalar…
CharlieThornton33 Jul 9, 2025
1dc613e
[skip ci] Fix padding for non-reversed small head-size arrows
CharlieThornton33 Jul 18, 2025
73d9532
[skip ci] Use += and -= abbreviations
CharlieThornton33 Jul 18, 2025
2b83aff
[skip ci] Change layout of vertex array for non-reversed LArrow head …
CharlieThornton33 Jul 18, 2025
e94a777
Improve clarity of DArrow padding code
CharlieThornton33 Jul 24, 2025
98d4bc4
Make What's New example simpler and more informative
CharlieThornton33 Jul 25, 2025
2ac0bff
Implement simplified padding rules
CharlieThornton33 Aug 9, 2025
a6e2abf
Fix padding for darrows
CharlieThornton33 Sep 9, 2025
f8ba249
Style padding code consistently between larrow and darrow
CharlieThornton33 Sep 9, 2025
7b4b3b1
[ci doc] Move what's new page to releases directory
CharlieThornton33 Sep 9, 2025
119a051
[skip ci] Make head-width validation clearer
CharlieThornton33 Sep 11, 2025
80d1c40
Move head-angle validation into constructor
CharlieThornton33 Sep 11, 2025
460306e
Remove references to 'text' for describing original box
CharlieThornton33 Sep 11, 2025
201e62c
[skip ci] Fix accidental paste into docstring
CharlieThornton33 Sep 11, 2025
94fa82d
Fix nomenclature (arrow tail -> arrow shaft)
CharlieThornton33 Sep 11, 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
Comment thread
CharlieThornton33 marked this conversation as resolved.
Resolved
-------------------------------------------------------------------

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
Comment thread
CharlieThornton33 marked this conversation as resolved.
Resolved
# 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
# ========== ============== ==========================
# ========== ============== ==========================
Comment thread
CharlieThornton33 marked this conversation as resolved.
Resolved
# 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