MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_locator_set_formatter

Function test_locator_set_formatter

lib/matplotlib/tests/test_dates.py:298–327  ·  view source on GitHub ↗

Test if setting the locator only will update the AutoDateFormatter to use the new locator.

()

Source from the content-addressed store, hash-verified

296
297
298def test_locator_set_formatter():
299 """
300 Test if setting the locator only will update the AutoDateFormatter to use
301 the new locator.
302 """
303 plt.rcParams["date.autoformatter.minute"] = "%d %H:%M"
304 t = [datetime.datetime(2018, 9, 30, 8, 0),
305 datetime.datetime(2018, 9, 30, 8, 59),
306 datetime.datetime(2018, 9, 30, 10, 30)]
307 x = [2, 3, 1]
308
309 fig, ax = plt.subplots()
310 ax.plot(t, x)
311 ax.xaxis.set_major_locator(mdates.MinuteLocator((0, 30)))
312 fig.canvas.draw()
313 ticklabels = [tl.get_text() for tl in ax.get_xticklabels()]
314 expected = ['30 08:00', '30 08:30', '30 09:00',
315 '30 09:30', '30 10:00', '30 10:30']
316 assert ticklabels == expected
317
318 ax.xaxis.set_major_locator(mticker.NullLocator())
319 ax.xaxis.set_minor_locator(mdates.MinuteLocator((5, 55)))
320 decoy_loc = mdates.MinuteLocator((12, 27))
321 ax.xaxis.set_minor_formatter(mdates.AutoDateFormatter(decoy_loc))
322
323 ax.xaxis.set_minor_locator(mdates.MinuteLocator((15, 45)))
324 fig.canvas.draw()
325 ticklabels = [tl.get_text() for tl in ax.get_xticklabels(which="minor")]
326 expected = ['30 08:15', '30 08:45', '30 09:15', '30 09:45', '30 10:15']
327 assert ticklabels == expected
328
329
330def test_date_formatter_callable():

Callers

nothing calls this directly

Calls 7

set_minor_locatorMethod · 0.80
set_minor_formatterMethod · 0.80
subplotsMethod · 0.45
plotMethod · 0.45
set_major_locatorMethod · 0.45
drawMethod · 0.45
get_textMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…