Skip to content

Commit da518ba

Browse files
committed
Merge pull request matplotlib#3078 from andreasWallner/fix_axis_margins_call_args
fix argument checks in axis/base.margins
2 parents 6288d8e + fcc865e commit da518ba

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ def margins(self, *args, **kw):
18251825
mx = my = args[0]
18261826
elif len(args) == 2:
18271827
mx, my = args
1828-
else:
1828+
elif len(args) > 2:
18291829
raise ValueError("more than two arguments were supplied")
18301830
if mx is not None:
18311831
self.set_xmargin(mx)

lib/matplotlib/tests/test_axes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,6 +3287,25 @@ def test_pie_ccw_true():
32873287
# Set aspect ratio to be equal so that pie is drawn as a circle.
32883288
plt.axis('equal')
32893289

3290+
@cleanup
3291+
def test_margins():
3292+
# test all ways margins can be called
3293+
data = [1, 10]
3294+
3295+
fig1, ax1 = plt.subplots(1, 1)
3296+
ax1.plot(data)
3297+
ax1.margins(1)
3298+
assert_equal(ax1.margins(), (1, 1))
3299+
3300+
fig2, ax2 = plt.subplots(1, 1)
3301+
ax2.plot(data)
3302+
ax2.margins(1, 0.5)
3303+
assert_equal(ax2.margins(), (1, 0.5))
3304+
3305+
fig3, ax3 = plt.subplots(1, 1)
3306+
ax3.plot(data)
3307+
ax3.margins(x=1, y=0.5)
3308+
assert_equal(ax3.margins(), (1, 0.5))
32903309

32913310
@cleanup
32923311
def test_pathological_hexbin():

0 commit comments

Comments
 (0)