Skip to content

FIX DateFormatter for month names when usetex=True - #19849

Merged
tacaswell merged 2 commits into
matplotlib:masterfrom
smartlixx:FIX_date_usetex
May 14, 2021
Merged

tacaswell merged 2 commits into
matplotlib:masterfrom
smartlixx:FIX_date_usetex

Conversation

@smartlixx

Copy link
Copy Markdown
Contributor

PR Summary

close #19836

Although a little bit clumsy, this PR can serve as the interim solution to the format of month names when usetex=True. At a long term, some alternative way should be considered, as proposed by @anntzer.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Comment thread lib/matplotlib/dates.py Resolved
@smartlixx
smartlixx requested a review from anntzer April 2, 2021 08:18
@anntzer
anntzer removed their request for review April 2, 2021 08:43
Comment thread lib/matplotlib/tests/test_dates.py Resolved
@smartlixx
smartlixx force-pushed the FIX_date_usetex branch 3 times, most recently from 3f8c0b4 to 6a417bc Compare May 12, 2021 13:45
@smartlixx
smartlixx force-pushed the FIX_date_usetex branch 2 times, most recently from 63ba2ea to 5afc0f2 Compare May 12, 2021 14:19

@jklymak jklymak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me @aitikgupta ? @anntzer ?

@aitikgupta aitikgupta left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this wrapping fail when we want TeX 'symbols' alongside the date?
For example, ≥ 12th May, 2021, or ≈ August, 2021

import datetime
date = datetime.datetime.today()
str_date = date.strftime('%m/%d/%Y')

label = r"\geq " + str_date
# or
# label = r"\approx " + str_date

_wrap_in_tex(label)               -----> $\mathdefault{\}$geq$\mathdefault{ 05/12/2021}$

Whereas, previously it would've returned simply $\mathdefault{\geq 05/12/2021}$.

I'm not sure if this is a valid usecase, or if _wrap_in_tex is called like this, or even if this should be handled here, but if it is, it would probably mean adding a condition to escape characters if the word is starting with \.

If not, this looks good!

@jklymak

jklymak commented May 12, 2021

Copy link
Copy Markdown
Member

Currently its just a private method for DateFormatter so I think thats OK.

@tacaswell

Copy link
Copy Markdown
Member

@aitikgupta Good instinct! However, in this case because this is an internal function to one of our modules and it is only used in our module, we can make more assumptions about the input (like it is only used in ConiseDateFormatter so we can be less general, only worry about the cases that start with a text month (because we know we will only pass that in), but still get the benefit of de-duplicating a bunch of lines of code that we would have had to write 2x otherwise.

@tacaswell
tacaswell merged commit 3665241 into matplotlib:master May 14, 2021
@tacaswell tacaswell modified the milestones: v3.5.0, v3.4.3 May 14, 2021
@tacaswell

Copy link
Copy Markdown
Member

@meeseeksdev backport to v3.4.x

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request May 14, 2021
QuLogic added a commit that referenced this pull request May 14, 2021
…849-on-v3.4.x

Backport PR #19849 on branch v3.4.x (FIX DateFormatter for month names when usetex=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Month names not set as text when using usetex

6 participants