Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29c5644

Browse files
authored
Merge pull request #21625 from meeseeksmachine/auto-backport-of-pr-21568-on-v3.5.x
Backport PR #21568 on branch v3.5.x (Enhancing support for tex and datetimes)
2 parents b202243 + e98d508 commit 29c5644

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

lib/matplotlib/dates.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,11 @@ def _wrap_in_tex(text):
595595
p = r'([a-zA-Z]+)'
596596
ret_text = re.sub(p, r'}$\1$\\mathdefault{', text)
597597

598-
# Braces ensure dashes are not spaced like binary operators.
599-
ret_text = '$\\mathdefault{'+ret_text.replace('-', '{-}')+'}$'
598+
# Braces ensure symbols are not spaced like binary operators.
599+
ret_text = ret_text.replace('-', '{-}').replace(':', '{:}')
600+
# To not concatenate space between numbers.
601+
ret_text = ret_text.replace(' ', r'\;')
602+
ret_text = '$\\mathdefault{' + ret_text + '}$'
600603
ret_text = ret_text.replace('$\\mathdefault{}$', '')
601604
return ret_text
602605

lib/matplotlib/tests/test_dates.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
import pytest
88

9-
from matplotlib import rc_context
9+
from matplotlib import rc_context, style
1010
import matplotlib.dates as mdates
1111
import matplotlib.pyplot as plt
1212
from matplotlib.testing.decorators import image_comparison
@@ -323,13 +323,17 @@ def callable_formatting_function(dates, _):
323323

324324
@pytest.mark.parametrize('delta, expected', [
325325
(datetime.timedelta(weeks=52 * 200),
326-
[r'$\mathdefault{%d}$' % (year,) for year in range(1990, 2171, 20)]),
326+
[r'$\mathdefault{%d}$' % year for year in range(1990, 2171, 20)]),
327327
(datetime.timedelta(days=30),
328-
[r'Jan$\mathdefault{ %02d 1990}$' % (day,) for day in range(1, 32, 3)]),
328+
[r'$\mathdefault{1990{-}01{-}%02d}$' % day for day in range(1, 32, 3)]),
329329
(datetime.timedelta(hours=20),
330-
[r'$\mathdefault{%02d:00:00}$' % (hour,) for hour in range(0, 21, 2)]),
330+
[r'$\mathdefault{01{-}01\;%02d}$' % hour for hour in range(0, 21, 2)]),
331+
(datetime.timedelta(minutes=10),
332+
[r'$\mathdefault{01\;00{:}%02d}$' % minu for minu in range(0, 11)]),
331333
])
332334
def test_date_formatter_usetex(delta, expected):
335+
style.use("default")
336+
333337
d1 = datetime.datetime(1990, 1, 1)
334338
d2 = d1 + delta
335339

@@ -609,14 +613,14 @@ def test_concise_formatter_show_offset(t_delta, expected):
609613
'$\\mathdefault{25}$', '$\\mathdefault{29}$', 'Feb',
610614
'$\\mathdefault{05}$', '$\\mathdefault{09}$']),
611615
(datetime.timedelta(hours=40),
612-
['Jan$\\mathdefault{{-}01}$', '$\\mathdefault{04:00}$',
613-
'$\\mathdefault{08:00}$', '$\\mathdefault{12:00}$',
614-
'$\\mathdefault{16:00}$', '$\\mathdefault{20:00}$',
615-
'Jan$\\mathdefault{{-}02}$', '$\\mathdefault{04:00}$',
616-
'$\\mathdefault{08:00}$', '$\\mathdefault{12:00}$',
617-
'$\\mathdefault{16:00}$']),
616+
['Jan$\\mathdefault{{-}01}$', '$\\mathdefault{04{:}00}$',
617+
'$\\mathdefault{08{:}00}$', '$\\mathdefault{12{:}00}$',
618+
'$\\mathdefault{16{:}00}$', '$\\mathdefault{20{:}00}$',
619+
'Jan$\\mathdefault{{-}02}$', '$\\mathdefault{04{:}00}$',
620+
'$\\mathdefault{08{:}00}$', '$\\mathdefault{12{:}00}$',
621+
'$\\mathdefault{16{:}00}$']),
618622
(datetime.timedelta(seconds=2),
619-
['$\\mathdefault{59.5}$', '$\\mathdefault{00:00}$',
623+
['$\\mathdefault{59.5}$', '$\\mathdefault{00{:}00}$',
620624
'$\\mathdefault{00.5}$', '$\\mathdefault{01.0}$',
621625
'$\\mathdefault{01.5}$', '$\\mathdefault{02.0}$',
622626
'$\\mathdefault{02.5}$']),

0 commit comments

Comments
 (0)