-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
27
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.
+369
−34
Open
Changes from all commits
Commits
Show all changes
27 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 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,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() |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really need data for this example.