8000 Make margins error as claimed in doc-string · matplotlib/matplotlib@f07b234 · GitHub
[go: up one dir, main page]

Skip to content

Commit f07b234

Browse files
committed
Make margins error as claimed in doc-string
1 parent b45025d commit f07b234

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,7 @@ def margins(self, *margins, x=None, y=None, tight=True):
27052705
before calling :meth:`margins`.
27062706
"""
27072707

2708-
if margins and x is not None and y is not None:
2708+
if margins and (x is not None or y is not None):
27092709
raise TypeError('Cannot pass both positional and keyword '
27102710
'arguments for x and/or y.')
27112711
elif len(margins) == 1:

lib/matplotlib/tests/test_axes.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5734,21 +5734,17 @@ def test_set_margin_updates_limits():
57345734
assert ax.get_xlim() == (1, 2)
57355735

57365736

5737-
@pytest.mark.parametrize('err, args, kwargs, match',
5738-
((ValueError, (-1,), {},
5739-
'margin must be greater than -0.5'),
5740-
(ValueError, (1, -1), {},
5741-
'margin must be greater than -0.5'),
5742-
(ValueError, tuple(), {'x': -1},
5743-
'margin must be greater than -0.5'),
5744-
(ValueError, tuple(), {'y': -1},
5745-
'margin must be greater than -0.5'),
5746-
(TypeError, (1, ), {'x': 1, 'y': 1},
5747-
'Cannot pass both positional and keyword '
5748-
'arguments for x and/or y.'),
5749-
(TypeError, (1, 1, 1), {},
5750-
'Must pass a single positional argument for all*'),
5751-
))
5737+
@pytest.mark.parametrize('err, args, kwargs, match', (
5738+
(ValueError, (-1,), {}, r'margin must be greater than -0\.5'),
5739+
(ValueError, (1, -1), {}, r'margin must be greater than -0\.5'),
5740+
(ValueError, tuple(), {'x': -1}, r'margin must be greater than -0\.5'),
5741+
(ValueError, tuple(), {'y': -1}, r'margin must be greater than -0\.5'),
5742+
(TypeError, (1, ), {'x': 1, 'y': 1},
5743+
'Cannot pass both positional and keyword arguments for x and/or y'),
5744+
(TypeError, (1, ), {'x': 1},
5745+
'Cannot pass both positional and keyword arguments for x and/or y'),
5746+
(TypeError, (1, 1, 1), {}, 'Must pass a single positional argument'),
5747+
))
57525748
def test_margins_errors(err, args, kwargs, match):
57535749
with pytest.raises(err, match=match):
57545750
fig = plt.figure()

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def margins(self, *margins, x=None, y=None, z=None, tight=True):
489489
applies to 3D Axes, it also takes a *z* argument, and returns
490490
``(xmargin, ymargin, zmargin)``.
491491
"""
492-
if margins and x is not None and y is not None and z is not None:
492+
if margins and (x is not None or y is not None or z is not None):
493493
raise TypeError('Cannot pass both positional and keyword '
494494
'arguments for x, y, and/or z.')
495495
elif len(margins) == 1:

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,13 +1713,26 @@ def test_margins():
17131713
assert ax.margins() == (0, 0.1, 0)
17141714

17151715

1716-
def test_margins_errors():
1717-
fig = plt.figure()
1718-
ax = fig.add_subplot(projection='3d')
1719-
with pytest.raises(TypeError, match="Cannot pass"):
1720-
ax.margins(0.2, x=0.4, y=0.4, z=0.4)
1721-
with pytest.raises(TypeError, match="Must pass"):
1722-
ax.margins(0.2, 0.4)
1716+
@pytest.mark.parametrize('err, args, kwargs, match', (
1717+
(ValueError, (-1,), {}, r'margin must be greater than -0\.5'),
1718+
(ValueError, (1, -1, 1), {}, r'margin must be greater than -0\.5'),
1719+
(ValueError, (1, 1, -1), {}, r'margin must be greater than -0\.5'),
1720+
(ValueError, tuple(), {'x': -1}, r'margin must be greater than -0\.5'),
1721+
(ValueError, tuple(), {'y': -1}, r'margin must be greater than -0\.5'),
1722+
(ValueError, tuple(), {'z': -1}, r'margin must be greater than -0\.5'),
1723+
(TypeError, (1, ), {'x': 1},
1724+
'Cannot pass both positional and keyword'),
1725+
(TypeError, (1, ), {'x': 1, 'y': 1, 'z': 1},
1726+
'Cannot pass both positional and keyword'),
1727+
(TypeError, (1, ), {'x': 1, 'y': 1},
1728+
'Cannot pass both positional and keyword'),
1729+
(TypeError, (1, 1), {}, 'Must pass a single positional argument for'),
1730+
))
1731+
def test_margins_errors(err, args, kwargs, match):
1732+
with pytest.raises(err, match=match):
1733+
fig = plt.figure()
1734+
ax = fig.add_subplot(projection='3d')
1735+
ax.margins(*args, **kwargs)
17231736

17241737

17251738
@check_figures_equal(extensions=["png"])

0 commit comments

Comments
 (0)
0