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

Commit3aa65a3

Browse files
committed
Revert datetime usetex ticklabels to use default tex font.
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()```
1 parent2fe38b5 commit3aa65a3

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

‎lib/matplotlib/dates.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@
173173
importfunctools
174174
importlogging
175175
importmath
176-
importre
177176

178177
fromdateutil.rruleimport (rrule,MO,TU,WE,TH,FR,SA,SU,YEARLY,
179178
MONTHLY,WEEKLY,DAILY,HOURLY,MINUTELY,
@@ -605,16 +604,7 @@ def drange(dstart, dend, delta):
605604

606605

607606
def_wrap_in_tex(text):
608-
p=r'([a-zA-Z]+)'
609-
ret_text=re.sub(p,r'}$\1$\\mathdefault{',text)
610-
611-
# Braces ensure symbols are not spaced like binary operators.
612-
ret_text=ret_text.replace('-','{-}').replace(':','{:}')
613-
# To not concatenate space between numbers.
614-
ret_text=ret_text.replace(' ',r'\;')
615-
ret_text='$\\mathdefault{'+ret_text+'}$'
616-
ret_text=ret_text.replace('$\\mathdefault{}$','')
617-
returnret_text
607+
returnr"{\fontfamily{\familydefault}\selectfont "+text+"}"
618608

619609

620610
## date tickers and formatters ###

‎lib/matplotlib/tests/test_dates.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ def callable_formatting_function(dates, _):
322322

323323
@pytest.mark.parametrize('delta, expected', [
324324
(datetime.timedelta(weeks=52*200),
325-
[r'$\mathdefault{%d}$'%yearforyearinrange(1990,2171,20)]),
325+
range(1990,2171,20)),
326326
(datetime.timedelta(days=30),
327-
[r'$\mathdefault{1990{-}01{-}%02d}$'%dayfordayinrange(1,32,3)]),
327+
['1990-01-%02d'%dayfordayinrange(1,32,3)]),
328328
(datetime.timedelta(hours=20),
329-
[r'$\mathdefault{01{-}01\;%02d}$'%hourforhourinrange(0,21,2)]),
329+
['01-01%02d'%hourforhourinrange(0,21,2)]),
330330
(datetime.timedelta(minutes=10),
331-
[r'$\mathdefault{01\;00{:}%02d}$'%minuforminuinrange(0,11)]),
331+
['01 00:%02d'%minuforminuinrange(0,11)]),
332332
])
333333
deftest_date_formatter_usetex(delta,expected):
334334
style.use("default")
@@ -341,7 +341,8 @@ def test_date_formatter_usetex(delta, expected):
341341
locator.axis.set_view_interval(mdates.date2num(d1),mdates.date2num(d2))
342342

343343
formatter=mdates.AutoDateFormatter(locator,usetex=True)
344-
assert [formatter(loc)forlocinlocator()]==expected
344+
assert [formatter(loc)forlocinlocator()]== [
345+
r'{\fontfamily{\familydefault}\selectfont %s}'%sforsinexpected]
345346

346347

347348
deftest_drange():
@@ -636,24 +637,14 @@ def test_offset_changes():
636637

637638
@pytest.mark.parametrize('t_delta, expected', [
638639
(datetime.timedelta(weeks=52*200),
639-
['$\\mathdefault{%d}$'% (t, )fortinrange(1980,2201,20)]),
640+
range(1980,2201,20)),
640641
(datetime.timedelta(days=40),
641-
['Jan','$\\mathdefault{05}$','$\\mathdefault{09}$',
642-
'$\\mathdefault{13}$','$\\mathdefault{17}$','$\\mathdefault{21}$',
643-
'$\\mathdefault{25}$','$\\mathdefault{29}$','Feb',
644-
'$\\mathdefault{05}$','$\\mathdefault{09}$']),
642+
['Jan','05','09','13','17','21','25','29','Feb','05','09']),
645643
(datetime.timedelta(hours=40),
646-
['Jan$\\mathdefault{{-}01}$','$\\mathdefault{04{:}00}$',
647-
'$\\mathdefault{08{:}00}$','$\\mathdefault{12{:}00}$',
648-
'$\\mathdefault{16{:}00}$','$\\mathdefault{20{:}00}$',
649-
'Jan$\\mathdefault{{-}02}$','$\\mathdefault{04{:}00}$',
650-
'$\\mathdefault{08{:}00}$','$\\mathdefault{12{:}00}$',
651-
'$\\mathdefault{16{:}00}$']),
644+
['Jan-01','04:00','08:00','12:00','16:00','20:00',
645+
'Jan-02','04:00','08:00','12:00','16:00']),
652646
(datetime.timedelta(seconds=2),
653-
['$\\mathdefault{59.5}$','$\\mathdefault{00{:}00}$',
654-
'$\\mathdefault{00.5}$','$\\mathdefault{01.0}$',
655-
'$\\mathdefault{01.5}$','$\\mathdefault{02.0}$',
656-
'$\\mathdefault{02.5}$']),
647+
['59.5','00:00','00.5','01.0','01.5','02.0','02.5']),
657648
])
658649
deftest_concise_formatter_usetex(t_delta,expected):
659650
d1=datetime.datetime(1997,1,1)
@@ -664,7 +655,8 @@ def test_concise_formatter_usetex(t_delta, expected):
664655
locator.axis.set_view_interval(mdates.date2num(d1),mdates.date2num(d2))
665656

666657
formatter=mdates.ConciseDateFormatter(locator,usetex=True)
667-
assertformatter.format_ticks(locator())==expected
658+
assertformatter.format_ticks(locator())== [
659+
r'{\fontfamily{\familydefault}\selectfont %s}'%sforsinexpected]
668660

669661

670662
deftest_concise_formatter_formats():
@@ -1325,3 +1317,9 @@ def test_concise_formatter_call():
13251317
deftest_date_ticker_factory(span,expected_locator):
13261318
locator,_=mdates.date_ticker_factory(span)
13271319
assertisinstance(locator,expected_locator)
1320+
1321+
1322+
deftest_usetex_newline():
1323+
fig,ax=plt.subplots()
1324+
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d/%m\n%Y'))
1325+
fig.canvas.draw()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp