Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d32ae0

Browse files
committed
TST: move tests from test_figure to test_pyplot
This test is much more about pyplot that Figure
1 parent bad4195 commit 5d32ae0

File tree

2 files changed

+131
-131
lines changed

2 files changed

+131
-131
lines changed

lib/matplotlib/tests/test_figure.py

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -937,134 +937,3 @@ def test_subfigure_double():
937937
subfigsnest[1].supylabel('supylabel')
938938

939939
axsRight = subfigs[1].subplots(2, 2)
940-
941-
942-
def test_axes_kwargs():
943-
# plt.axes() always creates new axes, even if axes kwargs differ.
944-
plt.figure()
945-
ax = plt.axes()
946-
ax1 = plt.axes()
947-
assert ax is not None
948-
assert ax1 is not ax
949-
plt.close()
950-
951-
plt.figure()
952-
ax = plt.axes(projection='polar')
953-
ax1 = plt.axes(projection='polar')
954-
assert ax is not None
955-
assert ax1 is not ax
956-
plt.close()
957-
958-
plt.figure()
959-
ax = plt.axes(projection='polar')
960-
ax1 = plt.axes()
961-
assert ax is not None
962-
assert ax1.name == 'rectilinear'
963-
assert ax1 is not ax
964-
plt.close()
965-
966-
# fig.add_axes() always creates new axes, even if axes kwargs differ.
967-
fig = plt.figure()
968-
ax = fig.add_axes([0, 0, 1, 1])
969-
ax1 = fig.add_axes([0, 0, 1, 1])
970-
assert ax is not None
971-
assert ax1 is not ax
972-
plt.close()
973-
974-
fig = plt.figure()
975-
ax = fig.add_axes([0, 0, 1, 1], projection='polar')
976-
ax1 = fig.add_axes([0, 0, 1, 1], projection='polar')
977-
assert ax is not None
978-
assert ax1 is not ax
979-
plt.close()
980-
981-
fig = plt.figure()
982-
ax = fig.add_axes([0, 0, 1, 1], projection='polar')
983-
ax1 = fig.add_axes([0, 0, 1, 1])
984-
assert ax is not None
985-
assert ax1.name == 'rectilinear'
986-
assert ax1 is not ax
987-
plt.close()
988-
989-
# fig.add_subplot() always creates new axes, even if axes kwargs differ.
990-
fig = plt.figure()
991-
ax = fig.add_subplot(1, 1, 1)
992-
ax1 = fig.add_subplot(1, 1, 1)
993-
assert ax is not None
994-
assert ax1 is not ax
995-
plt.close()
996-
997-
fig = plt.figure()
998-
ax = fig.add_subplot(1, 1, 1, projection='polar')
999-
ax1 = fig.add_subplot(1, 1, 1, projection='polar')
1000-
assert ax is not None
1001-
assert ax1 is not ax
1002-
plt.close()
1003-
1004-
fig = plt.figure()
1005-
ax = fig.add_subplot(1, 1, 1, projection='polar')
1006-
ax1 = fig.add_subplot(1, 1, 1)
1007-
assert ax is not None
1008-
assert ax1.name == 'rectilinear'
1009-
assert ax1 is not ax
1010-
plt.close()
1011-
1012-
# plt.subplot() searches for axes with the same subplot spec, and if one
1013-
# exists, and the kwargs match returns it, create a new one if they do not
1014-
fig = plt.figure()
1015-
ax = plt.subplot(1, 2, 1)
1016-
ax1 = plt.subplot(1, 2, 1)
1017-
ax2 = plt.subplot(1, 2, 2)
1018-
# This will delete ax / ax1 as they fully overlap
1019-
ax3 = plt.subplot(1, 2, 1, projection='polar')
1020-
ax4 = plt.subplot(1, 2, 1, projection='polar')
1021-
assert ax is not None
1022-
assert ax1 is ax
1023-
assert ax2 is not ax
1024-
assert ax3 is not ax
1025-
assert ax3 is ax4
1026-
1027-
assert ax not in fig.axes
1028-
assert ax2 in fig.axes
1029-
assert ax3 in fig.axes
1030-
1031-
assert ax.name == 'rectilinear'
1032-
assert ax2.name == 'rectilinear'
1033-
assert ax3.name == 'polar'
1034-
plt.close()
1035-
1036-
# plt.gca() returns an existing axes, unless there were no axes.
1037-
plt.figure()
1038-
ax = plt.gca()
1039-
ax1 = plt.gca()
1040-
assert ax is not None
1041-
assert ax1 is ax
1042-
plt.close()
1043-
1044-
# plt.gca() raises a DeprecationWarning if called with kwargs.
1045-
plt.figure()
1046-
with pytest.warns(
1047-
MatplotlibDeprecationWarning,
1048-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
1049-
ax = plt.gca(projection='polar')
1050-
ax1 = plt.gca()
1051-
assert ax is not None
1052-
assert ax1 is ax
1053-
assert ax1.name == 'polar'
1054-
plt.close()
1055-
1056-
# plt.gca() ignores keyword arguments if an axes already exists.
1057-
plt.figure()
1058-
ax = plt.gca()
1059-
with pytest.warns(
1060-
MatplotlibDeprecationWarning,
1061-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
1062-
ax1 = plt.gca(projection='polar')
1063-
assert ax is not None
1064-
assert ax1 is ax
1065-
assert ax1.name == 'rectilinear'
1066-
plt.close()
1067-
1068-
ax1 = plt.subplot(111, projection='polar')
1069-
ax2 = plt.subplot(111, polar=True)
1070-
assert ax1 is ax2

lib/matplotlib/tests/test_pyplot.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,134 @@ def test_subplot_reuse():
170170
assert ax2 is plt.gca()
171171
ax1 = plt.subplot(121)
172172
assert ax1 is plt.gca()
173+
174+
175+
def test_axes_kwargs():
176+
# plt.axes() always creates new axes, even if axes kwargs differ.
177+
plt.figure()
178+
ax = plt.axes()
179+
ax1 = plt.axes()
180+
assert ax is not None
181+
assert ax1 is not ax
182+
plt.close()
183+
184+
plt.figure()
185+
ax = plt.axes(projection='polar')
186+
ax1 = plt.axes(projection='polar')
187+
assert ax is not None
188+
assert ax1 is not ax
189+
plt.close()
190+
191+
plt.figure()
192+
ax = plt.axes(projection='polar')
193+
ax1 = plt.axes()
194+
assert ax is not None
195+
assert ax1.name == 'rectilinear'
196+
assert ax1 is not ax
197+
plt.close()
198+
199+
# fig.add_axes() always creates new axes, even if axes kwargs differ.
200+
fig = plt.figure()
201+
ax = fig.add_axes([0, 0, 1, 1])
202+
ax1 = fig.add_axes([0, 0, 1, 1])
203+
assert ax is not None
204+
assert ax1 is not ax
205+
plt.close()
206+
207+
fig = plt.figure()
208+
ax = fig.add_axes([0, 0, 1, 1], projection='polar')
209+
ax1 = fig.add_axes([0, 0, 1, 1], projection='polar')
210+
assert ax is not None
211+
assert ax1 is not ax
212+
plt.close()
213+
214+
fig = plt.figure()
215+
ax = fig.add_axes([0, 0, 1, 1], projection='polar')
216+
ax1 = fig.add_axes([0, 0, 1, 1])
217+
assert ax is not None
218+
assert ax1.name == 'rectilinear'
219+
assert ax1 is not ax
220+
plt.close()
221+
222+
# fig.add_subplot() always creates new axes, even if axes kwargs differ.
223+
fig = plt.figure()
224+
ax = fig.add_subplot(1, 1, 1)
225+
ax1 = fig.add_subplot(1, 1, 1)
226+
assert ax is not None
227+
assert ax1 is not ax
228+
plt.close()
229+
230+
fig = plt.figure()
231+
ax = fig.add_subplot(1, 1, 1, projection='polar')
232+
ax1 = fig.add_subplot(1, 1, 1, projection='polar')
233+
assert ax is not None
234+
assert ax1 is not ax
235+
plt.close()
236+
237+
fig = plt.figure()
238+
ax = fig.add_subplot(1, 1, 1, projection='polar')
239+
ax1 = fig.add_subplot(1, 1, 1)
240+
assert ax is not None
241+
assert ax1.name == 'rectilinear'
242+
assert ax1 is not ax
243+
plt.close()
244+
245+
# plt.subplot() searches for axes with the same subplot spec, and if one
246+
# exists, and the kwargs match returns it, create a new one if they do not
247+
fig = plt.figure()
248+
ax = plt.subplot(1, 2, 1)
249+
ax1 = plt.subplot(1, 2, 1)
250+
ax2 = plt.subplot(1, 2, 2)
251+
# This will delete ax / ax1 as they fully overlap
252+
ax3 = plt.subplot(1, 2, 1, projection='polar')
253+
ax4 = plt.subplot(1, 2, 1, projection='polar')
254+
assert ax is not None
255+
assert ax1 is ax
256+
assert ax2 is not ax
257+
assert ax3 is not ax
258+
assert ax3 is ax4
259+
260+
assert ax not in fig.axes
261+
assert ax2 in fig.axes
262+
assert ax3 in fig.axes
263+
264+
assert ax.name == 'rectilinear'
265+
assert ax2.name == 'rectilinear'
266+
assert ax3.name == 'polar'
267+
plt.close()
268+
269+
# plt.gca() returns an existing axes, unless there were no axes.
270+
plt.figure()
271+
ax = plt.gca()
272+
ax1 = plt.gca()
273+
assert ax is not None
274+
assert ax1 is ax
275+
plt.close()
276+
277+
# plt.gca() raises a DeprecationWarning if called with kwargs.
278+
plt.figure()
279+
with pytest.warns(
280+
MatplotlibDeprecationWarning,
281+
match=r'Calling gca\(\) with keyword arguments was deprecated'):
282+
ax = plt.gca(projection='polar')
283+
ax1 = plt.gca()
284+
assert ax is not None
285+
assert ax1 is ax
286+
assert ax1.name == 'polar'
287+
plt.close()
288+
289+
# plt.gca() ignores keyword arguments if an axes already exists.
290+
plt.figure()
291+
ax = plt.gca()
292+
with pytest.warns(
293+
MatplotlibDeprecationWarning,
294+
match=r'Calling gca\(\) with keyword arguments was deprecated'):
295+
ax1 = plt.gca(projection='polar')
296+
assert ax is not None
297+
assert ax1 is ax
298+
assert ax1.name == 'rectilinear'
299+
plt.close()
300+
301+
ax1 = plt.subplot(111, projection='polar')
302+
ax2 = plt.subplot(111, polar=True)
303+
assert ax1 is ax2

0 commit comments

Comments
 (0)