Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Revert datetime usetex ticklabels to use default tex font.#22361
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ba65596
to473f209
Compareret_text = '$\\mathdefault{' + ret_text + '}$' | ||
ret_text = ret_text.replace('$\\mathdefault{}$', '') | ||
return ret_text | ||
return r"{\fontfamily{\familydefault}\selectfont " + text + "}" |
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.
My matplotlib/latex integration ignorance is vast, but why do we need to do all the font selection here? (I guess I'm really asking why this needs to wrapped at all)
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.
Because tick formatters can only set the ticklabeltext, but not the ticklabel font (and moreover the way latex integration is set up right now, we don't even respect the font setting on Text object, but only the globalrcParams["font.family"]
, which is something that we should fix too...
So forcing the font via tex commands is using a big hammer to just go around all these limitations.
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.
But I mean, why isn't the default latex font acceptable? If I just put "23-Dec-2022" in a Latex document, that looks fine?
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.
See#2294 (comment): this is because we default to forcing non-math to sans-serif, which looks inconsistent with the serif numeric ticks. I agree with your point at#22350 (comment) that defaulting to sans-serif tex may not have been the best choice, but changing that would be somewhat trickier.
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...
with `{\fontfamily{\familydefault}\selectfont ...}`, instead of usingmath and selectively escaping parts of the string.Note that this is only possible now that tex strings are passed "all atonce" to the tex process rather than "one line at a time", because ifbreaking at `"\n"` as previously done, then the braces of the texcommand above would become unbalanced (and lines other than the firstwould not see the `\selectfont`).The main difference in rendering is that hyphens (e.g. in YY-MM-DD) arenow rendered as plain hyphens rather than minus signs, but some googlingsuggests that this is in fact correct (see e.g. ctan datetime2 orisodate packages). Also, month names are now rendered with serif, butthat seems more consistent with day and years which are also serifed(and which were the original source of all these issues).See also the script below, which reproduces the various issues raisedover the years:```pythonfrom datetime import datetime, timedeltafrom matplotlib.dates import ConciseDateFormatter, DateFormatterimport matplotlib.pyplot as pltimport numpy as npplt.rcdefaults(); plt.rcParams['text.usetex'] = Truefig, axs = plt.subplots(4, constrained_layout=True, figsize=(12, 4))t0 = datetime.now()ts = [t0 + i * timedelta(days=1) for i in range(10)]axs[0].plot(ts, range(10))axs[1].plot(ts, range(10))axs[1].xaxis.set_major_formatter(ConciseDateFormatter(axs[1].xaxis.get_major_locator()))ts = [t0 + i * timedelta(seconds=6) for i in range(100)]axs[2].plot(ts, range(100))axs[3].xaxis.set_major_formatter(DateFormatter('%d/%m\n%Y'))plt.show()```
Now ready to go. |
@anntzer do you consider this a bug fix that should be backported to 3.5.x? |
Probably not, given the amount of stuff that would need to be backported... |
PR Summary
with
{\fontfamily{\familydefault}\selectfont ...}
, instead of usingmath and selectively escaping parts of the string.
Note that this is only possible now that tex strings are passed "all at
once" to the tex process (#22360) rather than "one line at a time", because if
breaking at
"\n"
as previously done, then the braces of the texcommand above would become unbalanced (and lines other than the first
would not see the
\selectfont
).The main difference in rendering is that hyphens (e.g. in YY-MM-DD) are
now rendered as plain hyphens rather than minus signs, but some googling
suggests that this is in fact correct (see e.g. ctan datetime2 or
isodate packages). Also, month names are now rendered with serif, but
that seems more consistent with day and years which are also serifed
(and which were the original source of all these issues).
See also the script below, which reproduces the various issues raised
over the years:
Fixes#22350. Goes on top of#22359 and then#22360.
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).