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

Function test_concise_formatter

lib/matplotlib/tests/test_dates.py:566–612  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

564
565
566def test_concise_formatter():
567 def _create_auto_date_locator(date1, date2):
568 fig, ax = plt.subplots()
569
570 locator = mdates.AutoDateLocator(interval_multiples=True)
571 formatter = mdates.ConciseDateFormatter(locator)
572 ax.yaxis.set_major_locator(locator)
573 ax.yaxis.set_major_formatter(formatter)
574 ax.set_ylim(date1, date2)
575 fig.canvas.draw()
576 sts = [st.get_text() for st in ax.get_yticklabels()]
577 return sts
578
579 d1 = datetime.datetime(1997, 1, 1)
580 results = ([datetime.timedelta(weeks=52 * 200),
581 [str(t) for t in range(1980, 2201, 20)]
582 ],
583 [datetime.timedelta(weeks=52),
584 ['1997', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
585 'Sep', 'Oct', 'Nov', 'Dec']
586 ],
587 [datetime.timedelta(days=141),
588 ['Jan', '15', 'Feb', '15', 'Mar', '15', 'Apr', '15',
589 'May', '15']
590 ],
591 [datetime.timedelta(days=40),
592 ['Jan', '05', '09', '13', '17', '21', '25', '29', 'Feb',
593 '05', '09']
594 ],
595 [datetime.timedelta(hours=40),
596 ['Jan-01', '04:00', '08:00', '12:00', '16:00', '20:00',
597 'Jan-02', '04:00', '08:00', '12:00', '16:00']
598 ],
599 [datetime.timedelta(minutes=20),
600 ['00:00', '00:05', '00:10', '00:15', '00:20']
601 ],
602 [datetime.timedelta(seconds=40),
603 ['00:00', '05', '10', '15', '20', '25', '30', '35', '40']
604 ],
605 [datetime.timedelta(seconds=2),
606 ['59.5', '00:00', '00.5', '01.0', '01.5', '02.0', '02.5']
607 ],
608 )
609 for t_delta, expected in results:
610 d2 = d1 + t_delta
611 strings = _create_auto_date_locator(d1, d2)
612 assert strings == expected
613
614
615@pytest.mark.parametrize('t_delta, expected', [

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…