-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
CharlieThornton33
wants to merge
38
commits into
matplotlib:main
Choose a base branch
from
CharlieThornton33:road-sign-annotation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
2f366fa
Make arrow annotation arrowhead adjustable
Abitamim e8d7eb7
Add test - not sure if correct
Abitamim 15bd7dc
Update tutorial
Abitamim 4f57495
Fixed linting
Abitamim 5c3fa60
Add reversed arrow-head support to larrow/rarrow
CharlieThornton33 8065549
Fix reversed arrow-head support for single arrows, handle edge cases
CharlieThornton33 0471e92
Add support for reversed arrow-heads and edge cases in DArrow, update…
CharlieThornton33 212cbc9
Update docstings, add what's new notes
CharlieThornton33 273a2fe
Fix typo in DArrow drawing code
CharlieThornton33 bf2d06b
Fixed padding inconsistency: reverted breaking API change
CharlieThornton33 0ea2f5a
Fix what's new example
CharlieThornton33 d7fd405
Create unit test for boxarrow head adjustment
CharlieThornton33 ff34b4b
Fixed linting
CharlieThornton33 d9b0b32
Update new test to use mpl20 figure style
CharlieThornton33 f3369c0
Changed padding for LArrow/RArrow to prevent text spilling out
CharlieThornton33 3913ef6
[skip ci] Fix spelling mistake in LArrow padding code
CharlieThornton33 63a4ba9
Remove 'poking-out' behaviour from reversed arrow-heads, add padding …
CharlieThornton33 7ed9fd1
Remove now-unneeded manual padding from What's New page
CharlieThornton33 d953aef
Remove test_boxarrow_adjustment
CharlieThornton33 d2105da
Prevent text overspill from DArrows using padding
CharlieThornton33 54147e6
Added test for arrow-head adjustments
CharlieThornton33 b5ba28e
Fix padding from straight-edges of reversed arrow heads, fix incorrec…
CharlieThornton33 976e54b
[skip ci] Fix indentation in galleries/users_explain/text/annotations.py
CharlieThornton33 a08c67b
[skip ci] Use python % operator rather than np.mod() to act on scalar…
CharlieThornton33 1dc613e
[skip ci] Fix padding for non-reversed small head-size arrows
CharlieThornton33 73d9532
[skip ci] Use += and -= abbreviations
CharlieThornton33 2b83aff
[skip ci] Change layout of vertex array for non-reversed LArrow head …
CharlieThornton33 e94a777
Improve clarity of DArrow padding code
CharlieThornton33 98d4bc4
Make What's New example simpler and more informative
CharlieThornton33 2ac0bff
Implement simplified padding rules
CharlieThornton33 a6e2abf
Fix padding for darrows
CharlieThornton33 f8ba249
Style padding code consistently between larrow and darrow
CharlieThornton33 7b4b3b1
[ci doc] Move what's new page to releases directory
CharlieThornton33 119a051
[skip ci] Make head-width validation clearer
CharlieThornton33 80d1c40
Move head-angle validation into constructor
CharlieThornton33 460306e
Remove references to 'text' for describing original box
CharlieThornton33 201e62c
[skip ci] Fix accidental paste into docstring
CharlieThornton33 94fa82d
Fix nomenclature (arrow tail -> arrow shaft)
CharlieThornton33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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: true | ||
:alt: Six arrow-shaped text boxes, all containing the text "Arrow". The top left arrow has a shorter head than default, while the top right arrow a longer head. The centre left double arrow has a "road-sign" shape (head as wide as the arrow tail), while the centre right arrow has a "backwards" head. The bottom left arrow has two heads which are larger than default, and the bottom right arrow has a head narrower than its tail. | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
plt.text(0.2, 0.8, "Arrow", ha='center', size=16, bbox=dict(boxstyle="larrow, pad=0.3, head_angle=150")) | ||
plt.text(0.7, 0.8, "Arrow", ha='center', size=16, bbox=dict(boxstyle="rarrow, pad=0.3, head_angle=30")) | ||
plt.text(0.2, 0.2, "Arrow", ha='center', size=16, bbox=dict(boxstyle="darrow, pad=0.3, head_width=3")) | ||
plt.text(0.7, 0.2, "Arrow", ha='center', size=16, bbox=dict(boxstyle="larrow, pad=0.3, head_width=0.5")) | ||
plt.text(0.2, 0.5, "Arrow", ha='center', size=16, bbox=dict(boxstyle="darrow, pad=0.3, head_width=1, head_angle=60")) | ||
plt.text(0.7, 0.5, "Arrow", ha='center', size=16, bbox=dict(boxstyle="rarrow, pad=0.3, head_width=2, head_angle=-90")) | ||
|
||
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -378,7 +378,11 @@ class BoxStyle(_Style): | |
|
||
class LArrow(BoxStyle): | ||
pad: float | ||
def __init__(self, pad: float = ...) -> None: ... | ||
head_width: float | ||
head_angle: float | ||
Comment on lines
+381
to
+382
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these appear to be new public attributes, the tests should also check that modifying them after creation is working correctly. |
||
def __init__( | ||
self, pad: float = ..., head_width: float = ..., head_angle: float = ... | ||
) -> None: ... | ||
def __call__( | ||
self, | ||
x0: float, | ||
|
@@ -400,7 +404,11 @@ class BoxStyle(_Style): | |
|
||
class DArrow(BoxStyle): | ||
pad: float | ||
def __init__(self, pad: float = ...) -> None: ... | ||
head_width: float | ||
head_angle: float | ||
def __init__( | ||
self, pad: float = ..., head_width: float = ..., head_angle: float = ... | ||
) -> None: ... | ||
def __call__( | ||
self, | ||
x0: float, | ||
|
Binary file added
BIN
+56.5 KB
...lib/tests/baseline_images/test_arrow_patches/boxarrow_adjustment_test_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+40 Bytes
(100%)
lib/matplotlib/tests/baseline_images/test_arrow_patches/boxarrow_test_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.