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

Function test_concise_formatter_zformats

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

Source from the content-addressed store, hash-verified

791
792
793def test_concise_formatter_zformats():
794 zero_formats = ['', "'%y", '%B', '%m-%d', '%S', '%S.%f']
795
796 def _create_auto_date_locator(date1, date2):
797 fig, ax = plt.subplots()
798
799 locator = mdates.AutoDateLocator(interval_multiples=True)
800 formatter = mdates.ConciseDateFormatter(
801 locator, zero_formats=zero_formats)
802 ax.yaxis.set_major_locator(locator)
803 ax.yaxis.set_major_formatter(formatter)
804 ax.set_ylim(date1, date2)
805 fig.canvas.draw()
806 sts = [st.get_text() for st in ax.get_yticklabels()]
807 return sts
808
809 d1 = datetime.datetime(1997, 1, 1)
810 results = ([datetime.timedelta(weeks=52 * 200),
811 [str(t) for t in range(1980, 2201, 20)]
812 ],
813 [datetime.timedelta(weeks=52),
814 ["'97", 'Feb', 'Mar', 'Apr', 'May', 'Jun',
815 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
816 ],
817 [datetime.timedelta(days=141),
818 ['January', '15', 'February', '15', 'March',
819 '15', 'April', '15', 'May', '15']
820 ],
821 [datetime.timedelta(days=40),
822 ['January', '05', '09', '13', '17', '21',
823 '25', '29', 'February', '05', '09']
824 ],
825 [datetime.timedelta(hours=40),
826 ['01-01', '04:00', '08:00', '12:00', '16:00', '20:00',
827 '01-02', '04:00', '08:00', '12:00', '16:00']
828 ],
829 [datetime.timedelta(minutes=20),
830 ['00', '00:05', '00:10', '00:15', '00:20']
831 ],
832 [datetime.timedelta(seconds=40),
833 ['00', '05', '10', '15', '20', '25', '30', '35', '40']
834 ],
835 [datetime.timedelta(seconds=2),
836 ['59.5', '00.0', '00.5', '01.0', '01.5', '02.0', '02.5']
837 ],
838 )
839 for t_delta, expected in results:
840 d2 = d1 + t_delta
841 strings = _create_auto_date_locator(d1, d2)
842 assert strings == expected
843
844
845def test_concise_formatter_tz():

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…