8000 FIX DateFormatter for month names when usetex=True · matplotlib/matplotlib@cf92699 · GitHub
[go: up one dir, main page]

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

Appearance settings

Commit cf92699

Browse files
committed
FIX DateFormatter for month names when usetex=True
1 parent b6a6414 commit cf92699

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

lib/matplotlib/dates.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,21 @@ def drange(dstart, dend, delta):
592592

593593
def _wrap_in_tex(text):
594594
# Braces ensure dashes are not spaced like binary operators.
595-
return '$\\mathdefault{' + text.replace('-', '{-}') + '}$'
595+
p = re.compile("[a-zA-Z]+")
596+
m = p.finditer(text)
597+
cursor = 0
598+
ret_text = ''
599+
600+
for i in m:
601+
start = i.start()
602+
end = i.end()
603+
604+
ret_text += '$\\mathdefault{'+text[cursor:start].replace('-', '{-}')
605+
ret_text += '}$'+text[start:end]
606+
cursor = end
607+
608+
ret_text += '$\\mathdefault{'+text[cursor:].replace('-', '{-}')+'}$'
609+
return ret_text
596610

597611

598612
## date tickers and formatters ###

lib/matplotlib/tests/test_dates.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ def callable_formatting_function(dates, _):
271271
(datetime.timedelta(weeks=52 * 200),
272272
[r'$\mathdefault{%d}$' % (year,) for year in range(1990, 2171, 20)]),
273273
(datetime.timedelta(days=30),
274-
[r'$\mathdefault{Jan %02d 1990}$' % (day,) for day in range(1, 32, 3)]),
274+
[r'$\mathdefault{}$Jan$\mathdefault{ %02d 1990}$' % (day,)
275+
for day in range(1, 32, 3)]),
275276
(datetime.timedelta(hours=20),
276277
[r'$\mathdefault{%02d:00:00}$' % (hour,) for hour in range(0, 21, 2)]),
277278
])
@@ -284,6 +285,7 @@ def test_date_formatter_usetex(delta, expected):
284285
locator.axis.set_view_interval(mdates.date2num(d1), mdates.date2num(d2))
285286

286287
formatter = mdates.AutoDateFormatter(locator, usetex=True)
288+
print([formatter(loc) for loc in locator()])
287289
assert [formatter(loc) for loc in locator()] == expected
288290

289291

@@ -550,15 +552,16 @@ def test_concise_formatter_show_offset(t_delta, expected):
550552
(datetime.timedelta(weeks=52 * 200),
551553
['$\\mathdefault{%d}$' % (t, ) for t in range(1980, 2201, 20)]),
552554
(datetime.timedelta(days=40),
553-
['$\\mathdefault{Jan}$', '$\\mathdefault{05}$', '$\\mathdefault{09}$',
554-
'$\\mathdefault{13}$', '$\\mathdefault{17}$', '$\\mathdefault{21}$',
555-
'$\\mathdefault{25}$', '$\\mathdefault{29}$', '$\\mathdefault{Feb}$',
556-
'$\\mathdefault{05}$', '$\\mathdefault{09}$']),
555+
['$\\mathdefault{}$Jan$\\mathdefault{}$', '$\\mathdefault{05}$',
556+
'$\\mathdefault{09}$', '$\\mathdefault{13}$', '$\\mathdefault{17}$',
557+
'$\\mathdefault{21}$', '$\\mathdefault{25}$', '$\\mathdefault{29}$',
558+
'$\\mathdefault{}$Feb$\\mathdefault{}$', '$\\mathdefault{05}$',
559+
'$\\mathdefault{09}$']),
557560
(datetime.timedelta(hours=40),
558-
['$\\mathdefault{Jan{-}01}$', '$\\mathdefault{04:00}$',
561+
['$\\mathdefault{}$Jan$\\mathdefault{{-}01}$', '$\\mathdefault{04:00}$',
559562
'$\\mathdefault{08:00}$', '$\\mathdefault{12:00}$',
560563
'$\\mathdefault{16:00}$', '$\\mathdefault{20:00}$',
561-
'$\\mathdefault{Jan{-}02}$', '$\\mathdefault{04:00}$',
564+
'$\\mathdefault{}$Jan$\\mathdefault{{-}02}$', '$\\mathdefault{04:00}$',
562565
'$\\mathdefault{08:00}$', '$\\mathdefault{12:00}$',
563566
'$\\mathdefault{16:00}$']),
564567
(datetime.timedelta(seconds=2),

0 commit comments

Comments
 (0)
0