-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix minus signs in WCSAxes in TeX mode #16406
Conversation
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
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 catching and fixing this and sorry I didn't think more about tex mode in my PR. I would expect the new test to live next to the one I added in #15902, or even better, extend the existing test through pytest.mark.parametrize
. Any reason not to ?
(note that I'm currently working on fixing my own system where I just found that TeX is broken, so I couldn't run the test yet, but I'll report back)
No worries! I wasn't quite sure where to test this, but I guess I thought this test was covering |
No that's okay, you're right that you're testing a different bit of code, so it seems correct to have a separate test in hindsight. I was able to reprod and confirm that your patch fixed the problem locally. I'll do a detailed review now. |
angle=0, | ||
text=label, | ||
axis_displacement=0, | ||
data=(0, 0), |
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 know we're not going to look at these labels, so overlaps don't really matter, but it's still bugging me. Can we make data
depend on i
?
if usetex: | ||
label = f"$-{i}$" | ||
elif unicode_minus: | ||
label = f"\N{MINUS SIGN}{i}" | ||
else: | ||
label = f"-{i}" |
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 would prefer we avoid if
s in the body of the test when we can use parametrization instead. What I'm suggesting here is to use a single @pytest.mark.parametrize
decorator with three parameters: usetex
, unicode_minus
, and expected_labels
. It be less dynamic but would isolate the test logic from the input/expectation definition.
with mpl.rc_context( | ||
rc={"text.usetex": usetex, "axes.unicode_minus": unicode_minus} | ||
): | ||
ticklabels = TickLabels(None) |
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.
does this line also need to happen within the mpl.rc_context
?
I think it's just coming from that function's role in separating out the common prefix and the varying part of each tick label. Without putting the right kind of minus sign in Thanks for your review comments! I should have addressed them all. |
b69a20d
to
a959570
Compare
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 think it's just coming from that function's role in separating out the common prefix and the varying part of each tick label. Without putting the right kind of minus sign in skippable_chars, the minus sign gets shown for the first tick that has it, and then trimmed from successive ones.
thanks a bunch for this detailed explanation ! I think that this would be more obvious if they were more than 2 labels, so I suggest extending the test (it's a loop anyway) to use 4 or 5 of them.
After this round of review I think we'll be all set. Thank you !
data=(i, i), | ||
) | ||
expected_labels.append(label) | ||
ticklabels.simplify_labels() |
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.
actually I expect this line would be the only one that needs to happen within the rc_context, or am I missing something ?
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.
No, you're right!
rc={"text.usetex": usetex, "axes.unicode_minus": unicode_minus} | ||
): | ||
expected_labels = [] | ||
for i in [1, 2]: |
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.
for i in [1, 2]: | |
for i in range(1, 6): |
Alright, I've updated the test again. Thanks for reviewing! |
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.
LGTM now, thanks again !
…406-on-v6.1.x Backport PR #16406 on branch v6.1.x (Fix minus signs in WCSAxes in TeX mode)
Description
This is a small fix to #15902. For a moment in that PR, repeated minus signs were trimmed from axis labels, and that still happens when using matplotlib's TeX mode (note the bottom y tick):
This is because minuses are still hyphens in TeX mode (they should be, because LaTeX will render them right, and it happens because
formatter_locator._fix_minus
only looks at the first character of each label, which is$
in TeX mode). ButTickLabels.simplify_labels
still expects a unicode minus, so it trims the hyphen.This PR has
TickLabels.simplify_labels
expect hyphens in TeX mode, no matter theunicode_minus
setting.I added a test, but it's awkward because TeX tests are currently not run, pending #13326. If I force-enable TeX tests, the new test passes with this fix and fails without this fix: