현지화와 함께 변환기 등록
~.dates.ConciseDateConverter에 키워드 인수를 전달하고, 사용할 데이터 유형을 단위 레지스트리 (units registry) 에 등록하여 현지화와 함께 변환기를 등록할 수도 있습니다.
import datetime
formats = ['%y', ## ticks are mostly years
'%b', ## ticks are mostly months
'%d', ## ticks are mostly days
'%H:%M', ## hrs
'%H:%M', ## min
'%S.%f', ] ## secs
## these can be the same, except offset by one level....
zero_formats = [''] + formats[:-1]
## ...except for ticks that are mostly hours, then it's nice to have month-day
zero_formats[3] = '%d-%b'
offset_formats = ['',
'%Y',
'%b %Y',
'%d %b %Y',
'%d %b %Y',
'%d %b %Y %H:%M', ]
converter = mdates.ConciseDateConverter(
formats=formats, zero_formats=zero_formats, offset_formats=offset_formats)
munits.registry[np.datetime64] = converter
munits.registry[datetime.date] = converter
munits.registry[datetime.datetime] = converter
fig, axs = plt.subplots(3, 1, layout='constrained', figsize=(6, 6))
for nn, ax in enumerate(axs):
ax.plot(dates, y)
ax.set_xlim(lims[nn])
axs[0].set_title('Concise Date Formatter registered non-default')
plt.show()