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

Function test_extent_units

lib/matplotlib/tests/test_axes.py:9766–9797  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9764
9765@image_comparison(["extent_units.png"], style="mpl20")
9766def test_extent_units():
9767 _, axs = plt.subplots(2, 2)
9768 date_first = np.datetime64('2020-01-01', 'D')
9769 date_last = np.datetime64('2020-01-11', 'D')
9770 arr = [[i+j for i in range(10)] for j in range(10)]
9771
9772 axs[0, 0].set_title('Date extents on y axis')
9773 im = axs[0, 0].imshow(arr, origin='lower',
9774 extent=[1, 11, date_first, date_last],
9775 cmap=mpl.colormaps["plasma"])
9776
9777 axs[0, 1].set_title('Date extents on x axis (Day of Jan 2020)')
9778 im = axs[0, 1].imshow(arr, origin='lower',
9779 extent=[date_first, date_last, 1, 11],
9780 cmap=mpl.colormaps["plasma"])
9781 axs[0, 1].xaxis.set_major_formatter(mdates.DateFormatter('%d'))
9782
9783 im = axs[1, 0].imshow(arr, origin='lower',
9784 extent=[date_first, date_last,
9785 date_first, date_last],
9786 cmap=mpl.colormaps["plasma"])
9787 axs[1, 0].xaxis.set_major_formatter(mdates.DateFormatter('%d'))
9788 axs[1, 0].set(xlabel='Day of Jan 2020')
9789
9790 im = axs[1, 1].imshow(arr, origin='lower',
9791 cmap=mpl.colormaps["plasma"])
9792 im.set_extent([date_last, date_first, date_last, date_first])
9793 axs[1, 1].xaxis.set_major_formatter(mdates.DateFormatter('%d'))
9794 axs[1, 1].set(xlabel='Day of Jan 2020')
9795
9796 with pytest.raises(TypeError, match=r"set_extent\(\) got an unexpected"):
9797 im.set_extent([2, 12, date_first, date_last], clip=False)
9798
9799
9800def test_cla_clears_children_axes_and_fig():

Callers

nothing calls this directly

Calls 6

imshowMethod · 0.80
subplotsMethod · 0.45
set_titleMethod · 0.45
set_major_formatterMethod · 0.45
setMethod · 0.45
set_extentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…