Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
timhoffm merged 1 commit intomatplotlib:mainfromanntzer:datetex
Mar 29, 2022

Conversation

anntzer
Copy link
Contributor

PR Summary

with{\fontfamily{\familydefault}\selectfont ...}, instead of using
math 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 tex
command 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:

fromdatetimeimportdatetime,timedeltafrommatplotlib.datesimportConciseDateFormatter,DateFormatterimportmatplotlib.pyplotaspltimportnumpyasnpplt.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)foriinrange(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)foriinrange(100)]axs[2].plot(ts,range(100))axs[3].xaxis.set_major_formatter(DateFormatter('%d/%m\n%Y'))plt.show()

test

Fixes#22350. Goes on top of#22359 and then#22360.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).

ret_text = '$\\mathdefault{' + ret_text + '}$'
ret_text = ret_text.replace('$\\mathdefault{}$', '')
return ret_text
return r"{\fontfamily{\familydefault}\selectfont " + text + "}"
Copy link
Member

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)

Copy link
ContributorAuthor

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.

Copy link
Member

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?

Copy link
ContributorAuthor

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.

Copy link
Member

@jklymakjklymak left a 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()```
@anntzer
Copy link
ContributorAuthor

Now ready to go.

@timhoffmtimhoffm added this to thev3.6.0 milestoneMar 29, 2022
@timhoffmtimhoffm merged commitc98411e intomatplotlib:mainMar 29, 2022
@timhoffm
Copy link
Member

@anntzer do you consider this a bug fix that should be backported to 3.5.x?

@anntzer
Copy link
ContributorAuthor

Probably not, given the amount of stuff that would need to be backported...

timhoffm reacted with thumbs up emoji

@anntzeranntzer deleted the datetex branchMarch 29, 2022 21:39
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestSep 29, 2022
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestSep 29, 2022
kostyafarber pushed a commit to kostyafarber/matplotlib that referenced this pull requestOct 4, 2022
j1642 pushed a commit to j1642/matplotlib that referenced this pull requestOct 7, 2022
melissawm pushed a commit to melissawm/matplotlib that referenced this pull requestDec 19, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jklymakjklymakjklymak approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.6.0
Development

Successfully merging this pull request may close these issues.

[Bug]: text.usetex Vs. DateFormatter
4 participants
@anntzer@timhoffm@jklymak@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp