Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Implement head resizing (and reversal) for larrow/rarrow/darrow#29998
Conversation
… type hinting for LArrow/RArrow/DArrow
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join uson gitter for real-time discussion.
For details on testing, writing docs, and our review process, please seethe developer guide
We strive to be a welcoming and open project. Please follow ourCode of Conduct.
Hi everyone, I was just wondering whether someone would be willing to have a look at this PR? I feel like it's in a complete or nearly-complete state but need some guidance - the two failing CI jobs seem to be:
Any help would be greatly appreciated. Thanks! |
PR-cleanliness: This is a check so that we don't merge commits with unneeded images, which would increase repo size. You can either squash and force-push. Or ignore this and we'll squash-merge at the end. Ignore the macos test failure. It's unrelated. |
Thank you for getting back so quickly! Would it be okay if you handled the squashing - I'm relatively new to git, and I'm not sure of the best method to use for squashing to keep a relatively clean but traceable commit history? |
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.
Looking at the arrows in the test image,https://github.com/matplotlib/matplotlib/pull/29998/files#diff-ff8adb592a399d60ee5c93fbff7552182f53b74be4573ca21db404ef3c3a6673, the outline sometimes cuts through the text, which must not happen.
From plotting
plt.text(0.5, 0.5, 'text', size=24, bbox=dict(boxstyle="rarrow", fc="w", ec="k"),)plt.text(0.5, 0.5, 'text', size=24, bbox=dict(boxstyle="square", pad=0, fc="C0", ec='none'))
we can see that the original calculation had a shaft with the length of the text, i.e. the arrow head starts at -pad from the end of the text.
This setting was ok for the hard-coded parameters, but when head_size and head_angle can vary, we have to invest more into a good positioning of arrow head.
angle = -80 | ||
angle_step = 120 / repetitions | ||
for i in range(repetitions): | ||
for j, stylename in enumerate(sorted(styles)): | ||
if stylename in ("larrow", "rarrow", "darrow"): |
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.
Please explain what you are trying to achieve with this rather wild parameter juggling. I cannot follow the logic and the associated reference image looks complicated. I would have expected that you have a set of characteristic cases such as
{'head_width'=1.5, 'head_angle'=90},{'head_width'=1, 'head_angle'=60},{'head_witdh'=0.5, 'head_angle'=30},{'head_witdh'=1.5, 'head_angle'=-90},
for each of 'larrow', 'darrow', 'rarrow'. You could coveniently arrange them on a regular grid.
I don't think you need to test the rotation. By design that's covered by the transform system and is thus orthogonal to the shaping of the arrow. But if you want, you could add an extra entry with rotation in the above matrix.
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.
I wasn't aware that the transform system itself was tested elsewhere; I'll remove the rotations, as well as lay the arrows out more regularly. I was rushing quite a bit when writing the test, and I felt the positioning needed to somewhat resemble that intest_boxarrow
- the insane double loop is a result of me trying to test multiple cases for each type of arrow while still using the positioning code from that test.
Before I get on to rewriting the test, though, I'll work on the arrow head positioning/padding issue.
Since I'm going to need to make some relatively major changes to the contents of this PR (a redo of the arrow drawing code and a rewrite of its unit test), would it be better for me to amend my last commit (d9b0b32) as suggested in thecontributing guide, or make a few new commits? I'm not quite sure how to add more commits to an open PR - do I just push the changes to my development branch? |
@CharlieThornton33 yes you can just push more commits to your current branch and they will appear in this PR. Since you already have several commits they will ultimately need squashing one way or the other (and I see you already asked that we handle that), so I do not think you gain anything from the |
I've just redone the padding (only for
It's also a bit concerning that the CI workflow seems to run on every commit to this PR - am I okay to disable tests in my commit messages until the one where I write the new test to save on CI resources? |
I've just noticed - all of the |
@CharlieThornton33 I wouldn't worry about the CI failing, but if they are still running when you push another commit they will be interrupted and re-started. |
Hi, I'm a bit stuck with how to handle cases where an arrow head extends behind the opposite end of the body; something like I'm not sure whether the arrow head should 'stick out' through the other end of the body, or should cut off at that point. I'd really appreciate any advice - I don't know if there's any sort of precedent in Matplotlib for this kind of thing. |
I don't think there's precedent. While such cases should be rare, my gut feeling is that the tip should not stick out. |
Uh oh!
There was an error while loading.Please reload this page.
PR summary
When creating an annotation using boxed text in an arrow shape (
patches.BoxStyle.LArrow
/RArrow
/DArrow
),head_width
andhead_angle
arguments may now be passed to adjust the size of the arrow head(s), and (via the use of negative angles) generate 'reversed' arrow heads. Addresses#24618 and is a direct continuation of@Abitamim's work in#24744.This solves both the issue initially mentioned in#24618 (creating a pentagonal 'road-sign' annotation box), as well as allowing for many other customisation options for arrows; for example, a reversed-head
DArrow
could act as a way to bring attention to a certain region on an axis.A new test,
test_boxarrow_adjustment
, has been added to test these options.PR checklist